Let’s say I use curl –X GET command with the following link:


As you can see, there are some $variables in this string. Obviously, just adding them to the string without letting Bash know where these variables start and end won’t work.

So I tried to use all kinds of tags that I found (i.e. ‘”$Variable”’, ${Variable}, etc.) to separate variables and make this string look and act more like a normal request, but none of them worked. There were some related topics here, they were helpful, but information I got still didn’t make it work – probably because my case is a bit different from basic examples and I’m missing something here. Any ideas? Cheers!

  • Are you sure about that ;id=$ID before the query part (?...)? Jan 26 '15 at 14:44
  • Explain exactly what the problem is i.e. what should happen and what happens instead? Jan 26 '15 at 14:44
  • Why do you want to use -X GET (as opposed to letting curl forget the GET request properly)? Jan 26 '15 at 14:50

You don't seem to be escaping special characters properly; specifically ;, & and ?

Also, it may be a function of this website, but your double quotes aren't the quotes you're looking for: isn't the same as "

I'd use:

# curl "${WEBSITE_URL}/${ACTION_NAME}/${ACTION1}\;id=${ID}\?Command=TEST\&id1=${ID1}\&id2=${ID2}\&id3=${ID3}"


bash uses all characters after $ which are valid in a variable name to determine the name i.e. the first illegal char limits the name string.

In case of doubt ${Variable} should be used. You already mention that so your problem must be something different.

  • Strictly speaking $ introduces parameter expansion, variables being one type of parameters. For instance, 3, and # are not valid variable names but $3 and $# are valid parameter expansions. Also note that $12 is ${1}2 (in bash/ksh/yash/bourne, but not zsh/ash). Jan 26 '15 at 14:48

Create the string as a variable and pass that variable to curl.

echo $string #this should get the right string to be passed to curl
curl -X GET $string
  • That ; needs to be quoted or otherwise it will be considered as a variable separator. Using a variable won't really help here especially if you forget to quote it. Jan 26 '15 at 14:53
  • You're right, thanks for the comment. I'll modify the answer adding the missing quotes.
    – YoMismo
    Jan 26 '15 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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