Date: Thu, 11 Nov 2010 17:26:31 -0800 From: Devin Teske <dteske@vicor.com> To: freebsd-hackers@freebsd.org Subject: Re: Spinner Function for Shell Scripts Message-ID: <1289525191.30235.117.camel@localhost.localdomain> In-Reply-To: <1289506363.30235.113.camel@localhost.localdomain> References: <1289506363.30235.113.camel@localhost.localdomain>
next in thread | previous in thread | raw e-mail | index | archive | help
One-line fix for a small bug (see below). On Thu, 2010-11-11 at 12:12 -0800, Devin Teske wrote: > Hi fellow hackers... I come with baring gifts! > > So, just as the subject-line says, ... here's an efficient and robust > spinner function compatible with many shells. > > But, before I get into the code, > > [snip] > > eval_spin() > { > local commands= > if [ $# -gt 0 ]; then > # Take commands from positional arguments > while [ $# -gt 0 ]; do > commands="$commands${commands:+ }'$1'" > shift 1 > done > else > # Take commands from standard input > while read -r LINE; do > commands="$commands > $LINE" > done > fi > [ "$commands" ] || return $SUCCESS > > # > # Execute the command w/ spinner > # > ( > eval "$commands" > /dev/null 2>&1 The above line should instead be: ( eval "$commands" ) > /dev/null 2>&1 To protect from things such as: eval_spin exit > echo $? > ) | ( > n=1 > spin="/-\\|" > DONE= > > echo -n " " > while [ ! "$DONE" ]; do > DONE=$( /bin/sh -c 'read -t 0 DONE; echo $DONE' ) > printf "\b%s" $( echo "$spin" | sed -e \ > "s/.\{0,$(( $n % ${#spin} ))\}\(.\).*/\1/" ) > n=$(( $n + 1 )) > done > printf "\b \b" > exit $DONE > ) > } > > [snip] -- Cheers, Devin Teske -> CONTACT INFORMATION <- Business Solutions Consultant II FIS - fisglobal.com 510-735-5650 Mobile 510-621-2038 Office 510-621-2020 Office Fax 909-477-4578 Home/Fax devin.teske@fisglobal.com -> LEGAL DISCLAIMER <- This message contains confidential and proprietary information of the sender, and is intended only for the person(s) to whom it is addressed. Any use, distribution, copying or disclosure by any other person is strictly prohibited. If you have received this message in error, please notify the e-mail sender immediately, and delete the original message without making a copy. -> END TRANSMISSION <-
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1289525191.30235.117.camel>