【问题标题】:Shell if else nested loop errorShell if else 嵌套循环错误
【发布时间】:2013-05-20 14:02:28
【问题描述】:

这是我的脚本...我在下面收到此错误。我怀疑第二个如果其他错误但无法弄清楚..

read -p "Do you wish to continue the merge session? (y/n) " RESP
if [ "$RESP" = "y" ]; then
    co_repo=`echo $target_url | cut -d "/" -f 7`
    co_workspace="svn_promote_$co_repo"
    echo "$co_workspace ................................................."
    if [-d "$co_workspace" ] then;
        echo -e "Creating target workspace $co_workspace"
        echo -e ""
        mkdir $co_workspace
        echo -e "Checking out $target_url .."
        svn co $target_url $co_workspace
    else
        echo -e "Target workspace exists. Updating ..."
        svn update $co_workspace
    fi
else
    echo "Exiting promote session .."
fi

错误:

monday_try.sh: line 44: syntax error near unexpected token `else'
monday_try.sh: line 44: `                    else'

【问题讨论】:

    标签: shell loops if-statement scripting nested


    【解决方案1】:

    @Wumpus 所说的,以及

    if [-d "$co_workspace" ]
    

    [ 后面需要一个空格:

    if [ -d "$co_workspace" ]
    

    【讨论】:

    • @iaav,记住[是一个命令,有助于记住它需要被空格包围
    【解决方案2】:

    分号在之前 then,而不是在它之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多