日期:2014-05-16  浏览次数:20746 次

shell问题!求教!
#!/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 哪里错啦?



------解决方案--------------------
= 两边留个空格
------解决方案--------------------
主要是判断语句里面的等号两边漏下空格了。
JScript code

#!/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