2

I am looking for a pretty stupid piece of code for bash that will show a kind of "please wait" rolling display, with the characters : - \ | /

The first problem is that I don't know the name of this thing, so it is a bit difficult to find, and the other is could you please provide a scriptlet please ?

Thank you in advance,

Olivier

4 Answers 4

2

Thanks a lot for the valuable help. I had a look at all pieces of code, and they all seem pretty long for what I am doing.

So based on that I just redid a tiny piece of code I am sharing with you.

#! /bin/bash
state=1
delay=0.5
printf "-"
sleep $delay

while [ 1 ]
do
        printf "\b"
        case $state in
                0) printf "-";;
                1) printf "\\";;
                2) printf "|";;
                3) printf "/";;
        esac
        if [ $state -eq 3 ]
        then
                state=0;
        else
                state=$((state+1));
        fi
        sleep $delay
done

Of course, this can work as a standalone code, but take out the bash line, and you can insert it easily in a script, and eventually shrink it a bit more. The only thing is about the condition, which is now running forever, so have to get out your own condition for the stop.

Hope you'll find it useful. ;-)

1

They're called 'spinners'. Linux Journal has an article with example code.

5
  • 1
    Can you please include the answer here? Otherwise your post would become obsolete when the link goes down.
    – slhck
    Dec 25, 2013 at 10:27
  • 1
    I didn't post the answer because (a) it's quite a number of lines of code (especially if additional documentation is included) and I'm not sure if I'm allowed to copy them, (b) this SE isn't specifically about coding and (c) I thought the main question was 'what are these things called'
    – Teun Vink
    Dec 25, 2013 at 10:30
  • You could point to the archive.org copy at web.archive.org/web/20130405162038/http://www.linuxjournal.com/… instead. That is much less likely to go away. Dec 25, 2013 at 10:48
  • 1
    Pointing to an archive is one thing, but in essence we don't want users having to go somewhere else to get an answer. The OP also asked for a script if possible. Of course this is not Stack Overflow but that doesn't mean it's not allowed to post code in your answers :)
    – slhck
    Dec 25, 2013 at 10:52
  • His 'first problem' was what these things were called. I answered that. I'm happy to remove the link if that makes it any better. I'm not copying some code I can't take credit for or pointing to a site (partially) copying that site, in my opinion that's disrespectful towards the original author.
    – Teun Vink
    Dec 25, 2013 at 10:54
0

They're also called 'Throbbers'. For an implementation plus explanation how to use it see http://fitnr.com/showing-a-bash-spinner.html (disclaimer: I haven't tested it myself, but I overlooked it and it looks reasonable)

0

Could you try the below code for "please wait" process bar / spinners.

 #!/bin/bash
 echo -e "Please wait ..."
 while true;
 do
 echo -ne '-\r'
 sleep .2
 echo -ne '\\\r'
 sleep .2
 echo -ne '|\r'
 sleep .2
 echo -ne '/''\r'
 sleep .2
 echo -ne '-\r'
 done

or

try

 #!/bin/bash
 echo -n "Please wait..."
 while true
 do
      echo -n "."
      sleep .2
 done

Its working for me...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .