一、输入两个数,实现排序
代码:
#!/bin/bashread -p "please enter n m:" n m
if [ $n -gt $m ]
thentemp=$nn=$mm=$temp
fi
echo $n $m
运行结果
二、输入一个数判断是否水仙花数
代码:
echo narcissistic number
read -p "please enter num:" num
if [ $num -ge 100 -a $num -le 999 ]thenunit=$((num%10))decade=$((num/10%10))hundreds=$((num/100))sum=$((unit*unit*unit+decade*decade*decade+hundreds*hundreds*hundreds))if [ $num -eq $sum ]thenecho $num is narcissistic numberelseecho $num is not narcissistic numberfielseecho enetr error
fi
运行结果
三、输入成绩实现等级判断,A:90-100,B:80-89,C:70-79,D:0-69
代码
read -p "please enter score:" score
case $score in9[0-9]|100)echo A;;8[0-9])echo B;;7[0-9])echo C;;[0-6][0-9]|[0-9])echo D;;*)echo error;;
esac
运行结果