Following an example to do it.
function spinner() {
case $1 in
start)
let column=$(tput cols)-${#2}-8
echo -ne ${2}
printf "%${column}s"
local i sp n
sp='/-\|'
n=${#sp}
while sleep 0.1; do
printf "%s\b" "${sp:i++%n:1}"
done
;;
stop)
if [[ -z ${3} ]]; then
exit 1
fi
echo -e "\n"
kill $3 > /dev/null 2>&1
esac
}
function spinnerStart {
spinner "start" "${1}" &
pid=$!
disown
}
function spinnerStop {
spinner "stop" $1 $pid
unset pid
}
Following an example about how to use the above spinner.
spinnerStart 'Running my command ...' command <mySlowCommand> &>/dev/null spinnerStop $?