1 #!/bin/bash
2
3 # progressbar.sh
4 # print a progress bar
5 #
6 # Author: Jerry Fleming <jerryfleming2006@gmail.com>
7
8 function progress()
9 {
10 CHARS='|/-/'
11 CNT=0
12 while (($CNT <= 100)); do
13 pos=$(( $CNT % 4 ))
14 char=${CHARS:$pos:1}
15 echo -n "$char "
16 len=$( echo $CNT | wc -c )
17 echo -ne '/e[41m'
18 for((i=0; i<$len; i++));do echo -n " ";done
19 echo -ne '/e[44m'
20 for((i=$len+1; i<100; i++));do echo -n " ";done
21 echo -ne '/e[0m /e[1m'
22 echo -n "$CNT%"
23 echo -ne "/r"
24 CNT=$(( $CNT + 1))
25 #sleep .1
26 done
27 echo -e '/e[0m'
28 }
29
30 progress
31 echo
32 exit 0
33
运行效果如图
在终端下面显示一个进度条
最新推荐文章于 2024-05-23 09:32:53 发布