# **************************************************************
# This function display a progress process.
# To start the f_process function, you have to send the function
# into the background. To stop the f_progress function, you have
# to define the argument "stop".
#
# EXAMPLE:
#
# echo -n "Starting some daemon "; f_progress &
# if sleep 10; then
# f_progress "stop"; echo -e "\t[ OK ]"
# else
# f_progress "stop"; echo -e "\t[ FAILED ]"
# fi
#
function f_progress () {
local action=${1:-"start"}
declare -a sign=( "-" "/" "|" "\\\\" )
# define singnal file...
[ "$action" = "start" ] && echo 1 > /tmp/signal
[ "$action" = "stop" ] && echo 0 > /tmp/signal
while [ "$( cat /tmp/signal 2>/dev/null )" == "1" ] ; do
for (( i=0; i<${#sign[@]}; i++ )); do
echo -en "${sign[$i]}\b"
# with this command you can use millisecond as sleep time - perl rules ;-)
perl -e 'select( undef, undef, undef, 0.1 );'
done
done
# clear the last ${sign[$i]} sign at finish...
[ "$action" = "stop" ] && echo -ne " \b"
}