I think it's something like this: (Fedora14/bash)


for i in {0..10..1}; do echo -e "$i"'\c'
echo -e "\n\r"
sleep 1

But it doesn't work. Purpose: like this, but without the "clear":


for i in {0..10..1}; do echo -e "$i"
sleep 1

So a counting script that doesn't deletes the whole screen to output +1 number, instead it only deletes the line, where the counting is, so that there could be ex.: a beatifull "progress bar"..

for i in {0..15}; do echo -ne "$i"'\r'; sleep 1; done; echo 

You don't need ..1 for stepwidth 1 which is default.

echo -n 

prevents newlines.

\r is returning to begin of line (without newline - \n), and better than my formerly used '\b' for backstepping a single character, unhandy, if you have more than one digit-numbers. Thanks to rozcietrzewiacz.

  • You can also just use one \r instead of all the \b's. – rozcietrzewiacz Aug 30 '11 at 15:06
  • Yes, thanks, I changed my post accordingly. – user unknown Aug 30 '11 at 21:17

Are you looking for something like this?

for i in {1..10}; do 
  printf '\r%2d' $i
  sleep 1
printf '\n'
  • Why the first printf? – rozcietrzewiacz Aug 30 '11 at 14:40
  • It would make sense if you were counting backwards from 10 to 1 – glenn jackman Aug 30 '11 at 14:44
  • @rozcietrzewiacz and glenn jackman: I think i put it, without thinking too much, remembering a case where the numbers had different lengths, so that something old could be leaved on screen. – enzotib Aug 30 '11 at 14:56
  • @glen Really? How exactly? – rozcietrzewiacz Aug 30 '11 at 15:02
  • I missed the '%2d' in the next printf. If it had just been for i in {10..1..-1}; do printf "\r%d" $i; sleep 1; done then you would have seen 10, 90, 80, 70, etc – glenn jackman Aug 30 '11 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.