Status bar in bash

First of all, thank you all for your help. I can see the successful completion of my project in a couple of days.

I need to know how to put the status bar in a Script shell, 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

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

Thanks kiran

+3
source share
2 answers

You can print \rto go back to the beginning of the line so you can overwrite the last one printed with the new message:

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

It seems that only the number $Iwill change.

+6
source

$index. ((index++)). script

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
+3

Source: https://habr.com/ru/post/1734213/


All Articles