4个shell写的进度条脚本
example1:
- #!/bin/sh
- b=''
- for ((i=0;$i<=100;i+=2))
- do
- printf "progress:[%-50s]%d%%\r" $b $i
- sleep 0.1
- b=#$b
- done
- echo
效果:
example 2:
- #!/bin/bash
- i=0
- while [ $i -lt 20 ]
- do
- ((i++))
- echo -ne "=>\033[s"
- echo -ne "\033[40;50H"$((i*5*100/100))%"\033[u\033[1D"
- usleep 50000
- done
- echo
效果:
example 3:
- #!/bin/bash
- COUNTER=0
- _R=0
- _C=`tput cols`
- _PROCEC=`tput cols`
- tput cup $_C $_R
- printf "["
- while [ $COUNTER -lt 100 ]
- do
- COUNTER=`expr $COUNTER + 1`
- sleep 0.1
- printf "=>"
- _R=`expr $_R + 1`
- _C=`expr $_C + 1`
- tput cup $_PROCEC 101
- printf "]%d%%" $COUNTER
- tput cup $_C $_R
- done
- printf "\n"
效果:
example 4:
- #!/bin/bash
- i=0
- while [ $i -lt 50 ]
- do
- ((i++))
- for j in '-' '\\' '|' '/'
- do
- echo -ne "$j\033[s"
- echo -ne "\033[40;50H"$((i*5*100/100))%"\033[u\033[1D"
- usleep 50000
- done
- done
- echo
效果: