一个shell实例

自己第一次写shell脚本,边学边仿照这写的,展现出来以供参考

#!/bin/bash
echo "***zodiac and constellation***(Press q exit)"
echo -n "Please input yout birthday(ex:20190327): "

while read input
do
	if [ $input == 'q' ]
	then	break
	fi
	len=${#input}
	#echo "--->$len"
	if [ $len != 8 ]
	then
		echo "input error"
		continue
	fi

	y=${input: 0: 4}
	year=`expr $y`

	m=${input: 4: 2}
	month=`expr $m`

	d=${input: 6}
	day=`expr $d`

	mdc=${input: 4}
	md=`expr $mdc`
	echo "$year/$month/$day"
	if [ "$month" -lt "01" ] || [ "$month" -gt "12" ]
	then
		echo "month error: $month"
		echo -n "Please input yout birthday(ex:20190327): "
		continue
	fi
	if [ "$day" -lt "1" ] || [ "$day" -gt "31" ]
	then
		echo "day error: $day"
		echo -n "Please input yout birthday(ex:20190327): "
		continue
	fi
	mod=`expr $year % 12`
	case $mod in
		0) echo "You were born in the year of Monkey."
		;;
		1) echo "You were born in the year of Rooster."
		;;
		2) echo "You were born in the year of Dog."
		;;
		3) echo "You were born in the year of Boar."
		;;
		4) echo "You were born in the year of Rat."
		;;
		5) echo "You were born in the year of Ox."
		;;
		6) echo "You were born in the year of Tiger."
		;;
		7) echo "You were born in the year of Hare."
		;;
		8) echo "You were born in the year of Dragon."
		;;
		9) echo "You were born in the year of Snake."
		;;
		10) echo "You were born in the year of Horse."
		;;
		11) echo "You were born in the year of Sheep."
		;;
	esac
	
	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 "Please input yout birthday(ex:20190327): "

done
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值