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 exampleSTRING='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 thingsI 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 libcurlI'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
Trouble with bash & variable command substitution
bash;scripting;curl
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[@]}