@ linux 下编写shell脚本实现算命大师
苏曙光老师的os实验给我整破防了
添加系统调用make了5次才过(明天补上过程)
写shell是第一次
网上看了很多,不知道是版本原因还是啥,一部分语句别人可以实现我却实现不了。。。
心酸
#!/bin/bash
echo "Press 0 exit"
echo -n "Please input yout birthday(ex:20001122): "
while read input
do
if [ $input -eq 0 ]
then
break
fi
len=${#input}
if [ $len -ne 8 ]
then
echo "input error"
continue
fi
y=${input:0:4}
year=`expr $y`
mod=`expr $year % 12`
mdc=${input:4}
md=`expr $mdc`
if [ $mod -eq 0 ]
then echo "You were born in the year of Monkey."
elif [ $mod -eq 1 ]
then echo "You were born in the year of Rooster."
elif [ $mod -eq 2 ]
then echo "You were born in the year of Dog."
elif [ $mod -eq 3 ]
then echo "You were born in the year of Boar."
elif [ $mod -eq 4 ]
then echo "You were born in the year of Rat."
elif [ $mod == 5 ]
then echo "You were born in the year of Ox."
elif [ $mod == 6 ]
then echo "You were born in the year of Tiger."
elif [ $mod == 7 ]
then echo "You were born in the year of rabite."
elif [ $mod == 8 ]
then echo "You were born in the year of Dragon."
elif [ $mod == 9 ]
then echo "You were born in the year of Snake."
elif [ $mod == 10 ]
then echo "You were born in the year of Horse."
else echo "You were born in the year of Sheep."
fi
if [ "$md" -le "0120" ]
then echo "Capricorn "
elif [ "$md" -ge "0121" ] && [ "$md" -le "0219" ]
then echo "Aquarius"
elif [ "$md" -ge "0220" ] && [ "$md" -le "0320" ]
then echo "Pisces "
elif [ "$md" -ge "0321" ] && [ "$md" -le "0410" ]
then echo "Aries "
elif [ "$md" -ge "0421" ] && [ "$md" -le "0521" ]
then echo "Taurus "
elif [ "$md" -ge "0522" ] && [ "$md" -le "0621" ]
then echo "Gemini "
elif [ "$md" -ge "0622" ] && [ "$md" -le "0722" ]
then echo "Cancer "
elif [ "$md" -ge "0723" ] && [ "$md" -le "0823" ]
then echo "Leo"
elif [ "$md" -ge "0824" ] && [ "$md" -le "0923" ]
then echo "Virgo "
elif [ "$md" -ge "0924" ] && [ "$md" -le "1023" ]
then echo "Libra "
elif [ "$md" -ge "1024" ] && [ "$md" -le "1122" ]
then echo "Scorpio "
elif [ "$md" -ge "1123" ] && [ "$md" -le "1221" ]
then echo "Sagittarius "
else echo "Capricorn "
fi
echo -n "Please input yout birthday(ex:20001122): "
done
健壮性还是达不到要求,但是也勉强跑了起来吧
写的时候感觉就是***空格真啥b
写完其实感觉还好
毕竟是一个入门的小程序
希望明天有时间补觉
(一个寝室只有一个不断网接口就nm离谱,建议phd请我吃饭hhh)