Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-31-2005, 12:34 PM   #1
Registered: Apr 2005
Location: Chicago, IL
Distribution: openSUSE 13.1
Posts: 357

Rep: Reputation: 31
adding a rotating - to my bash script

I'm working on a script right now and I would like to add a rotating - after some of my echo text lines. It wouldn't have to really be linked to anything. I just want it there for eye candy purposes, and to show progress is being made. Does anyone have a link, tutorial, etc, that explains how to do this, or could tell me what this is called so I could look it up. Your help would be greatly appreciated.
Old 08-31-2005, 12:53 PM   #2
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

It's pretty simple. You can echo backspaces with '\b' if you use the -e flag with 'echo', and you can suppress the newlines after an echo with -n.
echo -n "-"
while true
  sleep 1
  echo  -n -e "\b\\"
  sleep 1
  echo  -n -e "\b|"
  sleep 1
  echo  -n -e "\b/"
  sleep 1
  echo  -n -e "\b-"
Old 08-31-2005, 12:54 PM   #3
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Well, it's generally called a 'spinner'. You can use the \b escape sequence with echo to make echo backspace over a previous character. For example:
function spin_once {
    echo -n '-'
    sleep .1
    echo -ne '\b/'
    sleep .1
    echo -ne '\b|'
    sleep 1.
    echo -ne '\b\\\'
    sleep .1
for i in `seq 1 25` ; do spin_once ; done

Last edited by Matir; 08-31-2005 at 12:56 PM.
Old 08-31-2005, 01:05 PM   #4
Registered: Apr 2005
Location: Chicago, IL
Distribution: openSUSE 13.1
Posts: 357

Original Poster
Rep: Reputation: 31
Thank you so much, folks!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script adding autostart gnome script Coolrunr Programming 3 01-01-2009 02:23 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script for adding multiple users pilipk01 Linux - Newbie 4 01-12-2004 10:05 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 02:03 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration