Simple spin animation using shell script

Below shell script will do a simple animation of rotating “pipe” (|) .

We use an array called spinner, with elements : ( ‘|’ ‘/’ “–” ‘\’ ). We loop through the elements each 0.1 secs to make it look like the rotating animation.

#!/bin/bash

clear

spinner=( '|' '/' "--" '\' );

echo "This script creates an spinning animation for 10 secs. "
echo -e "****************************************************** \n\n"

spin() #spin function for rotating the array of \ | -- /
{
        while [ 1 ]
        do
                for i in ${spinner[@]};
                do
                        echo -ne "\r Work in Progress $i                                   ";
                        sleep 0.1;
                done;
        done
}

count() #function to wait for 10 secs while the animation spins
{
  spin &
  pid=$! #captures process id for last run process

  for i in `seq 1 10`
  do
          sleep 1;
  done
  set +m # to supress job control output message
  kill $pid 2>&1 > /dev/null 
  echo -ne "\r Task Completed.                                             "
  echo " "
}

count # call count function
Spin Animation

Leave a comment

Design a site like this with WordPress.com
Get started