条件表达式中的语法错误:意外令牌`;'

时间:2015-04-28 09:22:42

标签: bash shell if-statement

我有一个应该接受多个参数的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条件时,我收到上述错误。任何人都有任何想法?

1 个答案:

答案 0 :(得分:29)

elif [[ "$firstParam" == "update"]]; then 

应该是

elif [[ "$firstParam" == "update" ]]; then

"update"]]

之间的空格