如何解决错误:意外令牌附近的语法错误`do'

时间:2017-06-08 09:08:09

标签: bash shell jenkins

我试图用这种方式读取两个文件:

if [[ $COPY_PREV_DEPLOYMENT == true ]]; then
    echo [$JOB_NAME] Copying old environment variables of $OLD_APP app to the new environment variables of $NEW_APP app...
    cf env $NEW_APP | awk '/User-Provided/,/No staging env variables have been set/'| cut -f1 -d":" | tail -n +2 > env_variables.txt
    cf env $OLD_APP | awk '/User-Provided/,/No staging env variables have been set/'| cut -f2 -d":" | tail -n +2 > env_variables_values.txt
    paste env_variables.txt env_variables_values.txt | while read -r VARIABLE VALUE
    do
        cf set-env "$NEW_APP" "$VARIABLE" "$VALUE"
    done 
    echo [$JOB_NAME] Done.
fi

但我正面临这个问题

  

..... sh:第61行:意外令牌do' ......sh: line 61:附近的语法错误('

有人可以帮我解决吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

do条件之后,您不会使用ifdo... done主要用于loops。此外,似乎不需要括号来从cloudfoundry api包装此单个执行语句。

代码可能如下所示:

if [[ $COPY_PREV_DEPLOYMENT == true ]]; then
    echo $JOB_NAME Copying old environment variables of $OLD_APP app to the new environment variables of $NEW_APP app...
    cf env $NEW_APP | awk '/User-Provided/,/No staging env variables have been set/'| cut -f1 -d":" | tail -n +2 > env_variables.txt
    cf env $OLD_APP | awk '/User-Provided/,/No staging env variables have been set/'| cut -f2 -d":" | tail -n +2 > env_variables_values.txt
    paste env_variables.txt env_variables_values.txt | while read -r VARIABLE VALUE; do 
        cf set-env "$NEW_APP" "$VARIABLE" "$VALUE"
        done
    echo $JOB_NAME Done.
fi