ステータスバーを通じて道の一部を動作を停止します

トーマス・ハミルトン:

私はbashでタイマープログラムを書いていますし、私はそれが完成に近づくとステータスバーが色を変更したいです。最初の(緑色)及び第二(黄色)予想通りプログレスバー作品の第三。最後の3分の1(赤)が正しく表示されませんが、カウンタが動作し続けます。私は私の構文で間違って何をしているのですか?

#!/bin/sh
#USAGE:
#timer <minutes>
clear

#add colors
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
LtGrn='\033[1;32m'
NC='\033[0m' # No Color

BAR='+###################+###################+###################'   # this is full bar, e.g. 60 chars

echo -e "${PURPLE}======================================================================${NC}"
echo
echo -e "                    Setting Timer for: ${YELLOW} $1 ${NC} minutes"
echo -e " ${PURPLE}  \o|           ${RED} 25%            ${YELLOW} 50%            ${GREEN} 75%            ${PURPLE} |o/ ${NC}"

for i in {1..60}; do
  if [ $i -ge 41 ]
    then
    echo -ne "\r ${RED}     ${BAR:41:$i}" # print $i chars of $BAR from 0 position
    sleep $1                              # wait 1/60th of total time between "frames"
  fi
  if [ $i -ge 21 ] && [ $i -lt 41 ]
    then
    echo -ne "\r ${YELLOW}     ${BAR:21:$i}" # print $i chars of $BAR from 0 position
    sleep $1                                 # wait 1/60th of total time between "frames"
  fi
  if [ $i -lt 21 ]
    then
    echo -ne "\r ${GREEN}     ${BAR:0:$i}" # print $i chars of $BAR from 0 position
    sleep $1                                 # wait 1/60th of total time between "frames"
  fi
done

echo
echo
echo -e "${RED}   Times up! Next task${NC}"
echo
KamilCuk:

${var:a:b}抽出物は、サブストリングからの位置aの数b文字を。

私はあなたがしたいと思い${BAR:0:$i}、すべてのケースで。

echo -ne "\r ${RED}     ${BAR:0:$i}"
echo -ne "\r ${YELLOW}     ${BAR:0:$i}"

${BAR:21:$i}ので、ちょうど、仕事はどうなるの${#BAR}十分な長さです。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=33432&siteId=1