bash inline countdown 1

bash inline countdown

secs=$((5 * 60))
while [ $secs -gt 0 ]; do
   echo -ne "$secs\033[0K\r"
   sleep 1
   : $((secs--))

Here is what the above code is Doing:
1. It’s creating a variable called secs and setting it to 5 minutes (5 * 60 seconds).
2. It’s creating a while loop that will run as long as the value of secs is greater than 0.
3. It’s printing the value of secs to the screen, followed by a carriage return (\r).
4. It’s sleeping for 1 second.
5. It’s decrementing the value of secs by 1.
6. It’s repeating steps 3-5 until the value of secs is 0.

Similar Posts