Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

#!/bin/bash

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

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

#!/bin/bash

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

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"..

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted
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.

share|improve this answer
    
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
add comment

Are you looking for something like this?

for i in {1..10}; do 
  printf '\r%2d' $i
  sleep 1
done
printf '\n'
share|improve this answer
    
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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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