0

This question already has an answer here:

I have a bash script that does a curl request for a URL. All curl headers and information is contained in a variable, here is a simplified example

STRING="'http://www.mydomain.com/url' -H 'mydomain.com'"

I originally had the script working by doing echo and xargs to pass it, but I've been reading that it might not be a good way to do things

I ran into issues when just trying curl $STRING, and adding double quotes to make it curl "$STRING" now gives a curl error stating "curl: (1) Protocol "'http" not supported or disabled in libcurl"

I'm guessing there is some simple thing I am overlooking here possibly relating to the quotes and spaces (I tried escaping single quotes earlier and that just added them literally in the string)

If I echo $STRING it displays it as written with all quotes and single quotes, and doing echo $STRING | xargs curl does what I want correctly, it does curl with my string as it's input

marked as duplicate by Gilles bash Feb 14 '17 at 23:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

What's wrong with xargs, especially if it works?

Shell removes quotes that aren't result of any expansion, which means it won't remove the single quotes that result from the removal of the double quotes. Use an array instead:

args=('http://www.mydomain.com/url' -H 'mydomain.com')
curl "${args[@]}"
1

You appear to have an extra quote in your error before the word http that may be triggering it. You should try echoing out the string before the execution to ensure the syntax is correct.

"curl: (1) Protocol "'http" not supported or disabled in libcurl"
                     ^
  • If I echo $STRING it shows it like it should, a literal string of what I want to go after curl, echo returns this 'http://www.mydomain.com/url' -H 'mydomain.com' If I do echo $STRING | xargs curl it works perfectly that way – Kate N Feb 14 '17 at 20:56
  • It's a matter of getting the quotes interpreted correctly. Here is a FAQ on the topic. There are a few ways to go about putting the string on the command line, ideally by using an array. – jayson Feb 14 '17 at 21:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.