views:

59

answers:

2
+1  Q: 

Status bar in bash

Hello,

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

+2  A: 

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
ghostdog74
Thanks.. i Forgot to add.. :) Thanks for pointing it out
Kiran
I would not recommend using `clear` because that will wipe out any other sort of screen info that you may possibly want or add in the future. `tput hpa 0` or even echoing out a bunch of `\b` is a better way to go.
SiegeX
+2  A: 

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.

sth
+1 and deleted my answer because I like `\r` better than `tput hpa 0` since I'm sure its more portable.
SiegeX
This is what I was looking for.. Amazing.. Thanks
Kiran