LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   adding a rotating - to my bash script (https://www.linuxquestions.org/questions/programming-9/adding-a-rotating-to-my-bash-script-358870/)

Cinematography 08-31-2005 12:34 PM

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.

ilikejam 08-31-2005 12:53 PM

Hi.

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.
Code:

echo -n "-"
while true
do
  sleep 1
  echo  -n -e "\b\\"
  sleep 1
  echo  -n -e "\b|"
  sleep 1
  echo  -n -e "\b/"
  sleep 1
  echo  -n -e "\b-"
done

Dave

Matir 08-31-2005 12:54 PM

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:
Code:

#!/bin/bash
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


Cinematography 08-31-2005 01:05 PM

Thank you so much, folks! :)


All times are GMT -5. The time now is 12:01 PM.