Я пишу программу таймера на bash и хочу, чтобы строка состояния меняла цвета по мере приближения к завершению. Первая (зеленая) и вторая (желтая) треть индикатора выполнения работают как положено. Последняя треть (красная) не отображается правильно, но счетчик продолжает работать. Что я делаю неправильно в моем синтаксисе?
#!/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