shell问题!求教!

koala0923 2012-03-10 11:28:31
#!/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 哪里错啦?

...全文
65 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreamhunter_lan 2012-03-11
  • 打赏
  • 举报
回复
貌似字符串比较没空格的话就当赋值了
Arnold9009 2012-03-11
  • 打赏
  • 举报
回复
对于初学者,当shell脚本执行异常的时候,首先考虑一下是不是空格的原因
koala0923 2012-03-11
  • 打赏
  • 举报
回复
[Quote=引用楼主 koala0923 的回复:]
#!/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
ech……
[/Quote]
谢谢啊!还真是这个原因。
jialejiahi 2012-03-10
  • 打赏
  • 举报
回复
主要是判断语句里面的等号两边漏下空格了。

#!/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
qq120848369 2012-03-10
  • 打赏
  • 举报
回复
= 两边留个空格

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧