shell實現輸出進度條

方法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"


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章