bash – echo command with option to display the output on the same line.
Here is a nice little trick to display the output in the same line :
1
|
The trick here is simple, first we disable the <a class="zem_slink" title="Newline" rel="wikipedia" href="http://en.wikipedia.org/wiki/Newline">newline printed by <a class="zem_slink" title="Echo (command)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Echo_%28command%29">echo command with the ”-n” option and then we enable the interpretation of the <a class="zem_slink" title="Backslash" rel="wikipedia" href="http://en.wikipedia.org/wiki/Backslash">backslash characters with the ”-e” option. As the ”\r” is used as <a class="zem_slink" title="Carriage return" rel="wikipedia" href="http://en.wikipedia.org/wiki/Carriage_return">carriage return which brings you to the start of the line without the newline (like in <a class="zem_slink" title="Typewriter" rel="wikipedia" href="http://en.wikipedia.org/wiki/Typewriter">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 <a class="zem_slink" title="For loop" rel="wikipedia" href="http://en.wikipedia.org/wiki/For_loop">for loop would do the same:
1
2 3 4 5 6 7 |
<img class="size-medium wp-image-2555" title="bash screenshot for the script output" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/09/temp-300x170.gif" alt="bash screenshot for the script output" width="300" height="170" />
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)
Related Articles:
- 2010/06/06 colors in bash – script to display all the possible colors.
- 2010/09/01 Use the last command\’s output as input to a command without piping and bind to it to a key sequence in bash.
- 2010/08/13 tee to a file descriptor
- 2010/06/22 cdargs – bash cd command with bookmarks and browser.
- 2010/05/10 coproc help - a new feature in bash
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.