Linux bash Timer

本秂侑毒 提交于 2019-12-12 09:09:49

问题


Ok, stupid newbie question here. I thought I was making a countdown timer. This is supposed to count down from 5 and once it is at 0 then execute the echo "time is up clown" then end. What am I doing wrong here?

seconds=5
date1=$((`date +%s` + $seconds)); 
while [ "$date1" -ne `date +%s` ]; do 
  if (!$date1 -lt ((`date +%s` + $seconds)+1)); then
     echo "time is up clown";
  break;
  fi;
  echo -ne "$(date -u --date @$(($date1 - `date +%s` )) +%H:%M:%S)\r";
done

回答1:


#!/bin/bash
SECS=5
while [[ 0 -ne $SECS ]]; do
    echo "$SECS.."
    sleep 1
    SECS=$[$SECS-1]
done
echo "Time is up, clown."


来源:https://stackoverflow.com/questions/21424985/linux-bash-timer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!