hust_os_shell算命大师

hust is 专栏收录该内容
2 篇文章 0 订阅

@ 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)

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值