The tput and printf functions are required to print the progress bar in the shell.
# tput Row col cursor moves to row row column Col
# tput cols Gets the maximum number of columns in a window
# tput lines Get window max running script
# echo $LINENO Get the current line number of the cursor
function Getprostr ()
{
Pchar=$1
Ptotal=$2
Outstr= ""
Numcol= ' tput cols '
coltotal=$[$numcol/2/$ptotal]
For ((i=1;i<= $coltotal; i++));
Do
Outstr= "$outstr $pchar";
Done
Echo $outstr
}
function Progresshead ()
{
Outstr= ""
Ptotal=$1
Row=$2
Str= ' getprostr '-' $ '
For ((i=1;i<= $ptotal; i++));
Do
Outstr= "$outstr $str";
Done
Tput Cup $row 0
echo "$outstr-"
}
function Progress ()
{
Tput SC
Pvalue=$1
Ptotal=$2
Row=$3
Numcol= ' tput cols '
Gstr= ' getprostr ' = ' $ptotal '
Str= "$gstr >"
if [$pvalue = = $ptotal]; Then
str= "$GSTR ="
Fi
barcol=$[($pvalue-1) * (${#str}-1)]
percent=$[$pvalue *100/ptotal]
Tput Cup $row $barcol
echo "$str"
Tput Cup $row $[$numcol/2]
echo "[$percent%]"
Tput RC
}
Clear
cols= ' tput cols '
Rows= ' tput lines '
Curline= $LINENO
Progresshead 5 $[$LINENO-$curline-2]
progressrow=$[$LINENO-$curline-2]
#echo ""
Progresshead 5 $[$LINENO-$curline-3]
Progress 1 5 $progressrow
Sleep 1
Progress 2 5 $progressrow
Sleep 1
Progress 3 5 $progressrow
Sleep 1
Progress 4 5 $progressrow
Sleep 1
Progress 5 5 $progressrow
Output Result:
-----------------------------------------
========================================[100%]
-----------------------------------------
This article is from the "small Hebebe Technology Space" blog, please be sure to keep this source http://babyhe.blog.51cto.com/1104064/1612009
Shell Progress bar