方法1: #!/usr/bin/env bash i=0; str=""arr=("|" "/" "-" "\\")while [ $i -le 100 ]do let index=i%4 let indexcolor=i%8 let color=30+indexcolor printf "\e[0;$color;1m[%-100s][%d%%]%c\r" "$str" "$i" "${arr[$index]}" sleep 0.05 let i++ str+='#'done printf "\n"
方法2: #!#!/usr/bin/env bash i=0str=""arry=("\\" "|" "/" "-")while [ $i -le 100 ]do let index=i%4 if [ $i -le 20 ] then let color=44 let bg=34 elif [ $i -le 45 ] then let color=43 let bg=33 elif [ $i -le 75 ] then let color=41 let bg=31 else let color=42 let bg=32#根据功能需求还可以更改 fi printf "\033[${color};${bg}m%-s\033[0m %d %c\r" "$str" "$i" "${arry[$index]}" usleep 3000 let i=i+1 str+="#"done printf "\n"