输入 countdown + 秒数,就开始倒计时了
gnu date
function countdown(){ local now=$(date +%s) local end=$((now + $1)) while (( now < end )); do printf "%s\r" "$(date -u -d @$((end - now)) +%T)" sleep 0.25 now=$(date +%s) done echo }
osx date
function countdown(){ echo $2 local now=$(date +%s) local end=$((now + $1)) while (( now < end )); do printf "%s\r" "$(date -u -j -f %s $((end - now)) +%T)" sleep 0.25 now=$(date +%s) done }
参考:https://superuser.com/questions/850368/osx-bash-command-line-countdown-timer?answertab=votes#tab-top
Leave a Reply