Question

Firstly, Thanks everyone for all your help. I can see the successful completion of my project in couple of days..

I need to know how to put a status bar in Shell Script, something like this.

No_of_files=55
index=0

while [ $index -lt $No_of_files ]
do
     echo -en "$index of $No_of_Files Completed"
     index=$((index + 1))
done

Expected Result : 1 of 55 Completed 2 of 55 Completed

Every iteration, index should be replaced but not other characters.

Thanks Kiran

Was it helpful?

Solution

You can print \r to go back to the beginning of the line, so that you can overwrite the last thing printed with a new message:

for (( I=0 ; I < 10 ; I++ )); do
   echo -en "\r$I of 10 completed"
   sleep 1
done
echo

This looks like the just the $I number would be changing.

OTHER TIPS

you forgot to increment the $index variable. ((index++)). You can see here also for a script to do progress bar

here's a Poor man's version

No_of_files=55
index=0

while [ $index -lt $No_of_files ]
do
     echo -ne "\r$index of $No_of_files Completed"
     ((index++))
    sleep 1
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top