“如何修复BASH中的“语法错误附近”错误”

时间:2019-06-06 20:03:29

标签: bash shell kubectl

我为运行删除作业(如果存在)设置了新条件,但在生产情况下不起作用。

GNU bash,v4.3.48(1)-发行版(x86_64-pc-linux-gnu)

docker run -e GO_DEPENDENCY_LABEL_PIPE='XXXXX' -e CREDENTIAL_NAME='production.XXXXX' -e KUBE_TOKEN='XXXXX' -v /go/pipelines/deploy-portal-site-data/helm:/helm --add-host=api.production.XXXXX:00.000.000.000 --rm -t --entrypoint /bin/bash docker.XXXXX.com.br/kubectl-prod:latest --login -c "kubectl config set-credentials production.XXXXX --token=XXXXX; VerifyJob=0; [[  -ge 1 ]] && kubectl -n production delete job portal-site-data-production || echo 'There is no job at the moment'"

我希望输出清洁作业,但实际输出是

Creating /root/.helm/repository 
Creating /root/.helm/repository/cache 
Creating /root/.helm/repository/local 
Creating /root/.helm/starters 
Creating /root/.helm/cache/archive 
Creating /root/.helm/repository/repositories.yaml 
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com 
Adding local repo with URL: http://127.0.0.1:8879/charts 
$HELM_HOME has been configured at /root/.helm.
Not installing Tiller due to 'client-only' flag having been set
Happy Helming!
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈ 
"gfn-helm-repo" has been added to your repositories
/bin/bash: -c: line 0: conditional binary operator expected
/bin/bash: -c: line 0: syntax error near `1'
/bin/bash: -c: line 0: `kubectl config set-credentials production.XXXXX --token=XXXXX; VerifyJob=0; [[  -ge 1 ]] && kubectl -n production delete job portal-site-data-production || echo 'There is no job at the moment''

2 个答案:

答案 0 :(得分:2)

[[  -ge 1 ]]

我认为错误来自命令的这一部分。

正在测试“未定义”是否大于或等于1

答案 1 :(得分:1)

我删除了我的图表 helm delete portal-site-data-production --tiller-namespace production --purge

并将\放在“

之前
set -x
docker pull $DOCKER_HELM_PROD_IMAGE
docker run \
-e GO_DEPENDENCY_LABEL_PIPE='${GO_DEPENDENCY_LABEL_PIPE}' \
-e CREDENTIAL_NAME='${CREDENTIAL_NAME}' \
-e KUBE_TOKEN='${KUBE_TOKEN}' \
-v $PWD/helm:/helm \
--add-host=api.production.XXXXX:00.000.000.000 \
--rm -t --entrypoint /bin/bash \
$DOCKER_HELM_PROD_IMAGE \
--login -c "kubectl config set-credentials ${CREDENTIAL_NAME} --token=${KUBE_TOKEN}; VerifyJob=$(kubectl -n production get job| grep -c portal-site-data-production); \"[[ ${VerifyJob} -ge 1 ]]\" && kubectl -n production delete job portal-site-data-production || echo \"There is no job at the moment\""

现在好了,非常感谢大家。