C高级--shell脚本实现分支判断
题目:
分支结构结合test指令完成一下编程
1>判断闰年
2>输入一个数判断是否为偶数
3>使用test指令实现等级判断 90--100A 60--89B 0-50C 其他错误
代码如下:
#!/bin/bash
read -p "请输入一个年份:" year
if [ $((year%4)) -eq 0 -a $((year%100)) -ne 0 -o $((year%400)) -eq 0 ]
thenecho "$year年是闰年"
elseecho "$year年不是闰年"
fi
read -p "请输入一个整数:" int
if [ $int -gt 0 -a $((int%2)) -eq 0 ]
thenecho "$int是偶数"
elseecho "$int不是偶数"
fi
read -p "请输入一个成绩:" score
if [ $score -ge 90 -a $score -le 100 ]
thenecho "$score是等级A"
elif [ $score -ge 60 -a $score -le 89 ]
thenecho "$score是等级B"
elif [ $score -ge 0 -a $score -le 59 ]
thenecho "$score是等级C"
elseecho "输入有误 请重新输入"
fi
运行结果如图所示:
shell脚本部分思维导图: