SECONDS记录脚本从开始执行到结束所耗费的时间,单位为秒
vi runsec.sh
#!/bin/bash
#定义两个变量:count 记录循环次数、MAX为while循环条件
count=1
MAX=5
while [ "$SECONDS" -le "$MAX" ]
do
echo "This is the $count time to sleep."
let count=$count+1
sleep 2
done
echo "The running time of this script is $SECONDS"
./runsec.sh
This is the 1 time to sleep.
This is the 2 time to sleep.
This is the 3 time to sleep.
The running time of this script is 6