Shell if else嵌套循环错误

时间:2013-05-24 21:33:53

标签: shell loops if-statement scripting nested

这是我的脚本...我在下面收到此错误。我怀疑第二个是否有其他错误但却无法弄明白......

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'

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

@Wumpus说的是什么,再加上

if [-d "$co_workspace" ]

需要[之后的空格:

if [ -d "$co_workspace" ]