当前位置: 技术问答>linux和unix
shell问题!求教!
来源: 互联网 发布时间:2017-02-09
本文导语: #!/bin/sh echo "Is morning ? Please answer yes or no" read timeof echo $timeof if [ "$timeof"="no" ];then echo "Good morning" elif [ "$timeof"="yes" ];then echo "Good afternoon" else echo "Sorry, $timeof is not rencognized. Enter yes or no" exit ...
#!/bin/sh
echo "Is morning ? Please answer yes or no"
read timeof
echo $timeof
if [ "$timeof"="no" ];then
echo "Good morning"
elif [ "$timeof"="yes" ];then
echo "Good afternoon"
else
echo "Sorry, $timeof is not rencognized. Enter yes or no"
exit 1
fi
exit 0
为什么不管怎么输入都显示输出Good morning 哪里错啦?
echo "Is morning ? Please answer yes or no"
read timeof
echo $timeof
if [ "$timeof"="no" ];then
echo "Good morning"
elif [ "$timeof"="yes" ];then
echo "Good afternoon"
else
echo "Sorry, $timeof is not rencognized. Enter yes or no"
exit 1
fi
exit 0
为什么不管怎么输入都显示输出Good morning 哪里错啦?
|
= 两边留个空格
|
主要是判断语句里面的等号两边漏下空格了。
#!/bin/sh
echo "Is morning ? Please answer yes or no"
read timeof
if [ $timeof = "yes" ];then
echo "Good morning"
elif [ $timeof = "no" ];then
echo "Good afternoon"
else
echo "Sorry, $timeof is not rencognized. Enter yes or no"
fi