shell的问题

wugui414 2010-10-03 01:17:26
if[ "$1"=="hello" ];then
echo "Hello,how are you?"
elif[ "$1"=="" ];then
echo "You MUST input parameters, ex>$0 some word"
else
echo "The only parameter is 'hello'"
fi


这语法有错吗?为什么总是报这样的错误?
sh08.sh: line 9: syntax error near unexpected token `then'
sh08.sh: line 9: `if[ "$1"=="hello" ];then'
...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Linux-Torvalds 2010-12-16
  • 打赏
  • 举报
回复
新手的困惑。
wugui414 2010-10-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 steptodream 的回复:]

引用 2 楼 wugui414 的回复:

引用 1 楼 steptodream 的回复:

注意空格!!把你的和下面的对比一下
C/C++ code

#!/bin/sh
if [ "$1" == "hello" ];then
echo "Hello,how are you?"
elif [ "$1" == "" ];then
echo "You MUST input p……
[/Quote]

再次!再次!感谢!!!!!!
steptodream 2010-10-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wugui414 的回复:]

引用 1 楼 steptodream 的回复:

注意空格!!把你的和下面的对比一下
C/C++ code

#!/bin/sh
if [ "$1" == "hello" ];then
echo "Hello,how are you?"
elif [ "$1" == "" ];then
echo "You MUST input parameters, ex>$0 some wo……
[/Quote]
不止那一个地方
==前后也应该有空格
wugui414 2010-10-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 steptodream 的回复:]

注意空格!!把你的和下面的对比一下
C/C++ code

#!/bin/sh
if [ "$1" == "hello" ];then
echo "Hello,how are you?"
elif [ "$1" == "" ];then
echo "You MUST input parameters, ex>$0 some word"
else
echo "The only pa……
[/Quote]

谢了,发现问题了 ”if 这里有空格[]“
steptodream 2010-10-03
  • 打赏
  • 举报
回复
注意空格!!把你的和下面的对比一下

#!/bin/sh
if [ "$1" == "hello" ];then
echo "Hello,how are you?"
elif [ "$1" == "" ];then
echo "You MUST input parameters, ex>$0 some word"
else
echo "The only parameter is 'hello'"
fi



18,772

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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