Here is a nice little trick to display the output in the same line :
echo -ne "output\\r"
The trick here is simple, first we disable the newline printed by echo command with the \”-n\” option and then we enable the interpretation of the backslash characters with the \”-e\” option. As the \”\\r\” is used as carriage return which brings you to the start of the line without the newline (like in typewriter), we will use the same to get the desired effect. So, if you wanted a stopwatch for a 100 seconds on the console then this simple bash for loop would do the same:
for i in `seq 100 1`
echo -ne "$i\\r"
Have fun playing with this and comment if you find some other interesting use of the same.
Related articles by Zemanta
- Use the last command\’s output as input to a command without piping and bind to it to a key sequence in bash. (amit-agarwal.co.in)
- Guides: Shell Scripting For Beginners (brighthub.com)
- Writing Better Shell Scripts – Part 1 | Innovations Technology Solutions | Blog (innovationsts.com)