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

Viewed 168

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?

1 Answers

One possible solution I found:

sh -c 'exit 129'; echo $? | xargs -I '{}' curl -G "http://example.com?value={}";
Related