适用于Bash编程初学者小例子–第四篇

计算时间差.

#!/bin/bash

START_SEC=$SECONDS
sleep 65
END_SEC=$SECONDS

DIFF=$((END_SEC-START_SEC))

echo "$(($DIFF / 3600)) hours $(($DIFF % 3600 / 60)) minutes and $(($DIFF % 60)) seconds elapsed."


结果如下

image


参考资料

==============

https://stackoverflow.com/questions/8385627/subtract-two-variables-in-bash

https://stackoverflow.com/questions/8903239/how-to-calculate-time-elapsed-in-bash-script

posted on 2020-07-15 19:38  中道学友  阅读(54)  评论(0编辑  收藏

导航

技术追求准确,态度积极向上