View Full Version : Over write something already written in terminal
zootreeves
March 19th, 2006, 06:30 PM
I'm sure i've seen this done in various programs, but I couldn't find any info on how to do it.
How could I count from 1 - 10 without printing 12345678910 in the terminal, but printing 1, then overwrting 1 and printing 2 etc..
hod139
March 19th, 2006, 08:06 PM
#!/bin/bash
echo -n "1" # -n --> no newline
sleep 1s
i=2
while [ $i -le 10 ]
do
echo -n -e "\b${i}" # -e enables backslashed-escaped chars
# \b is backspace
i=$((i+1))
sleep 1s
done
echo "" # Add a newline
paulipe
March 20th, 2006, 07:09 AM
#!/bin/bash
echo -n "1" # -n --> no newline
sleep 1s
i=2
while [ $i -le 10 ]; do
echo -n -e "\b${i}" # -e enables backslashed-escaped chars
# \b is backspace
i=$((i+1))
sleep 1s;
done
echo "" # Add a newline
I tried hod139's code but i got a syntax error. It looks like the semi-colons are important for bash while-loop. Atleast for my breezy setup it is.
hod139
March 20th, 2006, 10:06 AM
Sorry about that. The word "do" must be on a new line after the while if I don't put a ";". I fixed it in my original post.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.