Shell count time

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash

start=$(date +%s)

echo ---------
#type your command, like: sleep 50
sleep 50

end=$(date +%s)

diff=$((end - start))

echo -e "\e[1;32m take time is: $diff \e[m"
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
echo Count:
tput sc


for count in `seq 0 40`
do
tput rc
tput ed
echo -n $count
sleep 1
done

用 tput sc 存储光标位置。在每次循环中,通过 tput rc 恢复之前的存储的光标位置,在终端中打印出新的 count 值,然后使用 tputs ed 清除从当前位置到行尾之间的所有内容。行被清空之后,脚本就可以显示出新的值。sleep 可以使脚本在每次循环迭代之间延迟1秒钟。

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~