笔记
作业
1. 输入两个数,实现两个数的排序。(shell脚本)
#!/bin/bash
function fun()
{
tmp=${arr[0]}
arr[0]=${arr[1]}
arr[1]=$tmp
}
read -p "please enter two number:" -a a
if ((arr[0]>arr[1]))
then
# tmp=${arr[0]}
# arr[0]=${arr[1]}
# arr[1]=$tmp
fun
echo ${arr[0]} ${arr[1]}
else
echo ${arr[0]} ${arr[1]}
fi
2. 输入一个数,计算是否是水仙花。(shell脚本)
#!/bin/bash
read -p "please enter a number:" num
if ((num > 99 && num < 999 && (num%10)**3+(num/10%10)**3+(num/100)**3==num))
then
echo yes
else
echo no
fi
3. 输入一个成绩实现登记判断 90-100A、80-89B、70-79C、60-69D、0-59E。(shell脚本)
#!/bin/bash
read -p "please enter score: " score
if ((score<=100 && score>=90))
then
echo A
elif ((score<90 && score>=80))
then
echo B
elif ((score<80 && score>=70))
then
echo C
elif ((score<70 && score>=60))
then
echo D
elif ((score<60 && score>=0))
then
echo E
else
echo score input error
fi