Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to put value from linux pipe into curl querystring param?

Tags:

bash

curl

I have a numeric output from command, let's say:

 sh -c 'exit 1' ; echo $?

or

bc <<< "1 + 1"

And I need to send it in GET request via curl, like http://example.com/?value=1

I've tried this:

sh -c 'exit 1' ; echo $? | curl -G -d @- http://example.com/

but it just got param with a name 1 and empty value.

I know I can do something like:

result=`sh -c 'exit 129' ; echo $?` | curl -G -d value=${result} http://example.com

but I'd like to keep the first part of command unchanged and modify only part after pipe. Is it possible?

like image 461
Alex Zaitsev Avatar asked Apr 08 '21 19:04

Alex Zaitsev


1 Answers

One possible solution I found:

sh -c 'exit 129'; echo $? | xargs -I '{}' curl -G "http://example.com?value={}";
like image 148
Alex Zaitsev Avatar answered Sep 20 '22 09:09

Alex Zaitsev