Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a "spinner"

Status
Not open for further replies.

pavNell

Technical User
Sep 27, 2002
178
US
How would I go about creating a "spinner". A spinner is that little progress indicater thingy that you sometimes see while a program is running.

-\|/- <-- characters used for a spinner, but how would I make it work. Thanks for any help.
 
This won't be the first time I've missed something obvious but ... I like the idea of showing a 'spinner' (I usually just output a dot after every few seconds or so many iterations of a loop) but ... how do you make use of it?

The only ways I can think of running one in a working script is to refresh the character after each iteration of a loop - which won't look very good if the loop takes a long time to run, or to run the process doing the work in the background while the spinner is displaying, which will work but introduces other messy problems (like checking for the first process ending).

Am I being dense?
 
Here's what I do for a count down timer, you could modify this to echo - / | \ at 1 second intervals.

timer=61

while [ $timer != '1' ]
do
timer=`expr $timer - 1`
if [ $timer -ge '10' ]
then
echo &quot;$timer\b\b\c&quot;
sleep 1
else
echo &quot;0$timer\b\b\c&quot;
sleep 1
fi
done --
| Mike Nixon
| Unix Admin
| ----------------------------
 
I think what I was wondering was: is there any way to run processes in parallel in a shell script? (other than by running one process in the background)

Otherwise the spinner will just be displaying while nothing else is happening or (if it displays in a loop) it is likely to be 'turning' so slowly it won't look very effective anyway.
 
Hmmm so you want to start a process that spawns another process that updates the screen independantely from the main process. I think it would mean splitting the screen into two areas. I've seen something like this before.I'll have a look around. --
| Mike Nixon
| Unix Admin
| ----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top