linux shell 命令之SECONDS

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

linux shell 命令之SECONDS

上一篇:「Linux」- 从MAC地址中获取IP地址 @20210329


下一篇:Linux之Centos8 系统安装