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

Mus*_*abe 22 bash shell if-statement

我有一个shell脚本,应该接受多个参数.

它可以接受参数"update"或"create".如果没有传递参数,则用户应该收到错误.但是,在构建我的if/elif条件时,我收到错误:

syntax error in conditional expression: unexpected token `;'
Run Code Online (Sandbox Code Playgroud)

代码:

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
Run Code Online (Sandbox Code Playgroud)

如果我有这样的脚本

if [[ "$firstParam" == "" ]]; then
    printf "${RED}Use this script as \"tzfrs update/new [projectName]\"${NC} \n"
    exit 1
fi
Run Code Online (Sandbox Code Playgroud)

错误处理工作,我看到以下消息

Use this script as "tzfrs update/new [projectName]"

但是,添加elif条件时我得到了上述错误.有人有什么想法?

Jah*_*hid 35

elif [[ "$firstParam" == "update"]]; then 
Run Code Online (Sandbox Code Playgroud)

应该

elif [[ "$firstParam" == "update" ]]; then
Run Code Online (Sandbox Code Playgroud)

用之间的空间"update"]]

  • 哇,这么愚蠢的错误。感谢那 !:) 必须再等 11 分钟才能接受答案 (3认同)
  • 我不敢相信我犯了这个错误!_而且_它是如此受欢迎! (2认同)