运算方式及运算符号
shell中常用的运算命令
举例执行:
#!/bin/bash
for ((i=10;i>0;i--))
do
((j+=i))
echo $j
done
执行结果:
作业
- 编写脚本,用运算和已经学过的shell语句写一个自定义时间的倒计时脚本。
#!/bin/bash
read -p "Please input minute and second:" x y
if [ -z $x ]
then
echo "Error:Please input minute!"
elif [ -z $y ]
then
echo "Error:Please input second!"
elif [ "$x" -gt "60" -o "$y" -gt "60" ]
then
echo "Error:the time you input is over range!"
exit
else
for ((i=$x*60+$y;i>0;i--))
do {
minute=$[$i/60]
second=$[$i%60]
clear
echo "count down $minute:$second"
sleep 1
}
done
fi
执行结果如下: