bash 条件表达式中的语法错误:意外标记‘;’
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29915382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
syntax error in conditional expression: unexpected token `;'
提问by Musterknabe
I have a shell script that should accept multiple arguments.
我有一个 shell 脚本,它应该接受多个参数。
It can either accept the argument "update" or "create". If no argument is passed, the user should get an error. However, when building my if/elif
condition I'm getting the error:
它可以接受参数“更新”或“创建”。如果没有传递参数,用户应该得到一个错误。但是,在构建我的if/elif
条件时,我收到错误消息:
syntax error in conditional expression: unexpected token `;'
The code:
编码:
firstParam=
echo $firstParam //update/create/{empty}
if [[ "$firstParam" == "" ]]; then
printf "${RED}Use this script as \"tzfrs update/new [projectName]\"${NC} \n"
exit 1
elif [[ "$firstParam" == "update"]]; then
printf "update"
exit 1
fi
If I have the script like this
如果我有这样的脚本
if [[ "$firstParam" == "" ]]; then
printf "${RED}Use this script as \"tzfrs update/new [projectName]\"${NC} \n"
exit 1
fi
The error handling works, and I'm seeing the following message
错误处理有效,我看到以下消息
Use this script as "tzfrs update/new [projectName]"
Use this script as "tzfrs update/new [projectName]"
However, when adding the elif
condition I'm getting the above error. Anyone any idea?
但是,在添加elif
条件时,出现上述错误。有人知道吗?
回答by Jahid
elif [[ "$firstParam" == "update"]]; then
should be
应该
elif [[ "$firstParam" == "update" ]]; then
with a space between "update"
and ]]
用之间的空间"update"
和]]