LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1057|回复: 3

新手提问 shell scripts

[复制链接]
发表于 2009-8-5 11:06:48 | 显示全部楼层 |阅读模式
vi test-ifthen.sh


if ["$1"=="hellp"];then
echo "Hello! How are you?"
elif ["$1"==""];then
echo "You must input paramenters"
else
echo "The only accept parameter is hello"
fi

sh test-ifthen.sh hello



[hello==hello]:command not found
[hello==]:command not found


这个问题是怎么回事?! 谢谢!!
发表于 2009-8-5 11:25:09 | 显示全部楼层
注意空格, '[' 和后面的条件之间必须有空格:

if [ "$1" == "hello" ];then
        echo "Hello! How are you?"
elif [ "$1" == "" ];then
        echo "You must input parameters"
else
        echo "The only accept parameter is hello"
fi
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-8-5 13:50:10 | 显示全部楼层
谢谢 楼上!!
回复 支持 反对

使用道具 举报

发表于 2009-8-18 20:50:25 | 显示全部楼层
偶来补充一下,[ 其实是一个命令 所以后面要空格, 就是 test命令,你可以man test下看看
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表