Shell Script with a Progress Bar
Do you wonder to write a shell script that can display a progress bar!! Those types of script look good and user-friendlier.
In this post, I am going to share how to write a simple shell script with Progress Bar.
To implement this what should I use ??
So here is the answer, I am going to use only the "echo" command and few options along with it.
Command: echo
Options used
-n: Don't append a new line
-e: enable interpretations of backslash escapes
\r: Go back beginning of the line with a new line
Please note we have to decide on the steps how much percentage we want to display. Make sure the last of each line should be in alignment. We can any steps in between as per action item
Sample Script
[himanshu@oel7 ~]$ cat progress_bar_test.sh
#!/bin/bash
##Progress Bar Sample Script##
echo "Work in progress"
echo -ne '= [10%]\r'
sleep 2
echo -ne '=== [30%]\r'
sleep 2
echo -ne '===== [50%]\r'
sleep 2
echo -ne '======= [70%]\r'
sleep 2
echo -ne '==========[100%]\r'
echo -ne '\n'
sleep 2
echo "Sample script Completed"
Sample Output
Post a Comment
Post a Comment