[nylug-talk] spinning slash

David Bristow
Sun Nov 19 18:10:33 EST 2006


On Sat, 2006-11-18 at 09:33 -0500, Sunny Dubey wrote:
> On Friday 17 November 2006 14:14, Paul Robbins wrote:
> > That's very straightforward. However, i am having difficulty converting it
> > to ksh or sh so it is portable to my Unix boxes too.
> >
> 
> CHARS="/ - \ |"
> 
> while true ; do
>     for i in $CHARS
>         do printf "\b${i}"
>         # whatever command you want
>         if  [ "$?" != "0" ] ; then
>             break
>         fi
>     done
> done
> 
> Works on NetBSD's ash, 'nuff said.  (and zsh)
> 

You can make this even more interesting.  What I usually use to do this
kind of thing is, instead of using \b, you use \r and make sure that
each new string overwrites as many characters as the string before.
That's how things like wget do their progress bars.  This usually means
that shorter strings that follow longer strings have to have trailing
spaces to erase the previous output fully.

so you could output percentages, like:

"\r  0%"
"\r  1%"
...
"\r 10%"
et cetera.

-- 
David Bristow
djbristow at optonline.net



More information about the nylug-talk mailing list