卷曲不适用于bashscript

时间:2016-08-24 08:38:36

标签: bash curl

我有一个包含以下内容的脚本:

TEST=`curl -v  -X GET http://xxx/v2/${PROJECT}/${IMAGE}/manifests/${DCD}`
TEST2="curl -v  -XGET http://xxx/v2/${PROJECT}/${IMAGE}/manifests/${DCD}"
echo "output"
echo ${TEST}
echo "output2"
echo ${TEST2}

这是TEST和TEST1的输出:

* Illegal characters found in URL
* Closing connection -1
output
        ##empty
output2
curl -v -XGET http://xxx:5000/v2/proj1/base/manifests/sha256:a1f97fd03ec62888fb315745cde69acb7c98d0fae7xxx

如果我复制output2(curl -v ...)的内容并执行它比它工作正常(这是我尝试在output1中做的)。所以似乎命令正确填写。但是该命令的执行(在output1中发生的事情)似乎失败了:在URL中发现了非法字符。

我真的不知道出了什么问题

包含cat -A

的脚本的全部内容
#!/bin/sh$
#ENV VAR to set in Jenkins Job$
PROJECT="proj1"$
IMAGE="base"$
TAG="1.2"$
$
# Find Docker-Content-Digest$
DCD=`curl -v -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://xxx:5000/v2/${PROJECT}/${IMAGE}/manifests/${TAG} 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}'`$
$
# Delete tag in registry using DCD$
# I just want to execute the command belowe but gave the illegal argument erros so tried some debugging with this$
TEST=`curl -v -X GET http://xxx:5000/v2/${PROJECT}/${IMAGE}/manifests/${DCD}`$
$
TEST2="curl -v -XGET http://xxx:5000/v2/${PROJECT}/${IMAGE}/manifests/${DCD}"$
echo "output"$
echo ${TEST}$
echo "output2"$
echo ${TEST2}$
$

1 个答案:

答案 0 :(得分:1)

解决方案是添加:

DCD=${DCD%$'\r'}

命令DCD =`curl -v ...

之后

所以它似乎是this问题的副本。