linux.ChinaUnix.net
首页 | 微博 | 新闻 | Linux | FreeBSD | AIX | Windows | 博客 | 论坛 | 存储 | 网络 | 人才 | Wiki | 资料 | 读书 | 手册 | 下载 | 空间 | 搜索
  免费注册 | 忘记密码 | 会员登录 | 搜索 | 帮助 


一个shell的问题

  首页 » 首页 » CU论坛 » Linux » 汇总贴列表 » 编程问题 »
[打印] [收藏] [本帖文本页] [推荐此主题给朋友]

一个很简单的shell,如下:
echo  "guess the color"
read COLOR
if [  “$COLOR”=="red"  ]  
then
         echo "correct"
elif [  “$COLOR”=="black" ]
then
         echo "too far"
else
         echo "not correct"
fi
逻辑有问题,输入任何字符串,输出correct,怎么回事


已解决,谢谢

[ 本帖最后由 tige 于 2008-11-12 15:12 编辑 ]



if [  $COLOR == "red"  ]
__________________________________
一直被模仿,从未被超越。
http://7717060.cublog.cn/



回复 #2 7717060 的帖子

已改,多谢,又有新的错误



回复 #1 tige 的帖子

你那是个 shell 脚本,不是 shell
__________________________________
What's done, is done!





QUOTE:
原帖由 tige 于 2008-11-11 20:16 发表
已改,多谢,又有新的错误


贴出来看看!
__________________________________
一直被模仿,从未被超越。
http://7717060.cublog.cn/



回复 #5 7717060 的帖子

line10: syntax error near  unexpected  token 'else '
line10: 'else'



少了一个then

hi everybody~
obviously,a word "then" is needed after "elif " in your shell script

codetest is ok~~)

#!/bin/bash                                                                                                   
#a problem in CU                                                                                                  
echo  "guess the color"
read COLOR
if [  $COLOR == "red"  ]
then
echo "correct"
elif [ $COLOR == "black" ]
then                                    <---------here
  echo "too far"
else
echo "not correct"
fi


best wishes



同意7楼,验证无误。
__________________________________
TNND,把知识都交出来!



写脚本还是多拿现成的东西该好一些,直接动手写难免这里那里出错,如果不是很熟悉的话
__________________________________
squid_front:http://bbs2.chinaunix.net/thread-1452375-1-1.html





QUOTE:
原帖由 north423 于 2008-11-12 09:43 发表
hi everybody~
obviously,a word "then" is needed after "elif " in your shell script

codetest is ok~~)

#!/bin/bash                                                                         ...


多谢了,错误倒是没了,但是逻辑不对了,我输入black,输出的是correct,我用的是==,这是怎么回事啊


  首页 » 论坛 » 编程问题 »
Copyright © 2001-2010 ChinaUnix.net All Rights Reserved     联系我们:

感谢所有关心和支持过ChinaUnix的朋友们    转载本站内容请注明原作者名及出处

京ICP证041476号


清除 Cookies - Linux时代 - Archiver - WAP - TOP

GMT+8, 2010-03-21 03:35, Processed in 0.030143 second(s), 7 queries, Gzip enabled.