【发布时间】:2021-02-03 14:51:14
【问题描述】:
我有一个应该接受多个参数的 shell 脚本。
它可以接受参数“更新”或“创建”。如果没有传递参数,用户应该得到一个错误。但是,在构建我的 if/elif 条件时,我遇到了错误:
syntax error in conditional expression: unexpected token `;'
代码:
firstParam=$1
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 [[ "$firstParam" == "" ]]; then
printf "${RED}Use this script as \"tzfrs update/new [projectName]\"${NC} \n"
exit 1
fi
错误处理有效,我看到以下消息
Use this script as "tzfrs update/new [projectName]"
但是,在添加 elif 条件时,我遇到了上述错误。有人知道吗?
【问题讨论】:
标签: bash shell if-statement