结合if..else..,test指令完成下述练习:
1)判断闰年
2)输入一个数判断是否为偶数
3)使用test指令实现等级判断 90--100A 60--89B 0-50C 其他错误
#!/bin/bash
#1、判断闰年: 能够被4整除且不能被100整除 或者 能够被400整除
read -p "input the year: " year
if [ $((year%4)) -eq 0 ] && [ $((year%100)) -ne 0 ] || [ $((year%400)) -eq 0 ]
then
echo "$year 是闰年."
else
echo "$year 不是闰年."
fi
#2、输入一个数,判断是否为偶数
read -p "input a number: " num
if [ $((num%2)) -eq 0 ]
then
echo "$num is even."
else
echo "$num is odd."
fi
#3、使用test指令实现等级判断
read -p "input a score: " s
if test $s -le 100 -a $s -ge 90
then
echo A
elif test $s -le 89 -a $s -ge 60
then
echo B
elif [ $s -le 50 -a $s -ge 0 ]
then
echo C
else
echo ERROR
fi