-2

If command1 is:

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)}' 

which output, for example, the following Docker-Content-Digest:

> sha256:12345...

knowing that running each command separately works, how to inject command1 output as part of command2 text as:

curl -k -v -u user:password -X DELETE https://example.com/v2/image/manifests/(command1 output)

I am just trying to run one command only!


Update:

When I combine them together using the double quote as following:

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)}')"

I get the following output and command2 never executed:

> * Illegal characters found in URL
> * Closing connection -1 
> * curl: (3) Illegal characters found in URL

Update 2

when I use single quote, I get the following output:

> < 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
polemon
  • 11,431
McLan
  • 269
  • 2
  • 8
  • echo "thisis$(echo "test")" or better using printf: printf 'thisis%s' "$(echo "test")" – pLumo Sep 28 '21 at 13:11
  • you want to use command substitution https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html

    echo thisis$(command1)

    – ralz Sep 28 '21 at 13:13
  • @rAlen see update please. substitution didn't work – McLan Sep 28 '21 at 13:30
  • @pLumo using variables is not as injecting the output in command text. PLease check my update – McLan Sep 28 '21 at 13:31
  • try putting "$(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)}')" put double quotes before and after $(), also what is the error you are getting, are you getting an error or wrong output that isn't an error – ralz Sep 28 '21 at 13:33
  • You are getting JSON back from that curl command. Consider showing that document. It's easier to parse JSON using jq than with grep and awk. – Kusalananda Sep 28 '21 at 13:34
  • @McLan Can you give more detail about how substitution "didn't work"? – DonHolgo Sep 28 '21 at 13:37
  • @rAlen still not working . please check question update – McLan Sep 28 '21 at 13:41
  • @DonHolgo Please check question update (the command I tried and the output) – McLan Sep 28 '21 at 13:41
  • 1
    @McLan your initial question and especially formatting was quite misleading and also very unclear what you wanted to achieve. Also I suggest reading how to ask in the help center. – polemon Sep 28 '21 at 14:00
  • Thank you @polemon for your your kind explanation. I just tried to ask a question with simplest syntax possible. – McLan Sep 28 '21 at 14:03
  • @McLan what do you get if you manually paste the output to the end of the URL, is curl working then, is the URL valid then. This is probably an issue with special characters like $ or ! inside URL which bash expands/substitutes to something else and then URL becomes unusable. If you have special characters like that in URL you need to escape them. – ralz Sep 28 '21 at 14:14

1 Answers1

1

I assume you mean:

echo "thisis $(echo 'test')"

Depending on what you actually want to achieve, you can try a bunch of things:

  1. You can substitute each part of the command pipe and see where the error is. So far, you didn't do any actual debugging, as far as I can see.

  2. You could simply assign the output of the first command into a variable:

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"

Obviously I can't debug any of that, as I don't have access to the actual result set of either command - that's for you to try and debug further.

I any event, the $(…) syntax is called command substitution, and it's explained in the man pages of shells that support it (which is pretty much every single modern one).

polemon
  • 11,431