如果command1是:
curl -k -v -u user:password https://example.com/v2/image/manifests/tag -H Accept: application/vnd.docker.distribution.manifest.v2+json 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}' 例如,它的输出是以下Docker-Content-Digest:
> sha256:12345...知道单独运行每个命令后,如何将command1输出作为command2文本的一部分注入如下:
curl -k -v -u user:password -X DELETE https://example.com/v2/image/manifests/(command1 output)我只是试着只运行一个命令!
更新:
当我使用双引号将它们组合在一起时,如下所示:
curl -k -v -u user:password -X DELETE https://example.com/v2/image/manifests/"$(curl -k -v -u user:password https://example.com/v2/image/manifests/tag -H Accept: application/vnd.docker.distribution.manifest.v2+json 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}')"我得到了以下输出,command2从未执行过:
> * Illegal characters found in URL
> * Closing connection -1
> * curl: (3) Illegal characters found in URLUpdate 2
当我使用单引号时,我得到以下输出:
> < HTTP/1.1 404 Not Found
< Server: nginx/1.21.3
< Date: Tue, 28 Sep
> 2021 13:46:50 GMT
< Content-Type: text/plain; charset=utf-8 <
> Content-Length: 19
< Connection: keep-alive <
> Docker-Distribution-Api-Version: registry/2.0 <
> X-Content-Type-Options: nosniff < 404 page not found发布于 2021-09-28 13:11:32
我猜你是说:
echo "thisis $(echo 'test')"根据你实际想要达到的目标,你可以尝试一些事情:
CMD1=$(curl -k -v -u user:password https://example.com/v2/image/manifests/tag -H Accept: application/vnd.docker.distribution.manifest.v2+json 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}')
curl -k -v -u user:password -X DELETE https://example.com/v2/image/manifests/"$CMD1"显然,我无法调试其中的任何一个,因为我无法访问这两个命令的实际结果集--这需要您进一步尝试和调试。
无论如何,$(…)语法被称为命令替换,它在支持它的shell手册页中作了解释(几乎每一个现代语法都是这样)。
https://unix.stackexchange.com/questions/670986
复制相似问题