Here's a little script that displays a spinner until the command given to it is done.
#!/bin/bash
if [[ -z "$*" ]] ; then
echo "Usage: $0 command [args] ..."
exit 0
fi
"$@" &
echo -n "Running '$@'... "
BACKSPACE='\010'
SPINNER='|/-\'
INDEX=0
while kill -0 $! 2>/dev/null ; do
echo -n -e "${SPINNER:$INDEX:1}"
sleep 0.2
(( INDEX = ($INDEX + 1) % 4 ))
echo -n -e "$BACKSPACE"
done
echo -e "${BACKSPACE}done."
Example usage:
$ ./spinner sleep 3
Running 'sleep 3'... [spinner displayed here]
After a while:
$ ./spinner sleep 3
Running 'sleep 3'... done.
$
(My way of bash scripting is based on trial-and-error, so suggestions for improving this script are very welcome.)