Shell Progress bar

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.