Overwrite previous output in Bash instead of appending it

Posted by NES on Ask Ubuntu See other posts from Ask Ubuntu or by NES
Published on 2010-12-04T11:43:08Z Indexed on 2011/02/03 23:34 UTC
Read the original article Hit count: 421

Filed under:
|
|

For a bash timer i use this code:

#!/bin/bash
sek=60
echo "60 Seconds Wait!"
echo -n "One Moment please "
while [ $sek -ge 1 ]
do
   echo -n "$sek "  
sleep 1
   sek=$[$sek-1]
done
echo
echo "ready!"

That gives me something like that

One Moment please: 60 59 58 57 56 55 ...

Is there a possibility to replace the last value of second by the most recent so that the output doesn't generate a large trail but the seconds countdown like a real time at one position? (Hope you understand what i mean :))

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about bash