ambikanair
ambikanair

Reputation: 4590

Unable to append shell variables to curl command

I am trying to store password in a shell variable. Once this step is done, I need to use this password in a curl command.

logmetPassword=$(echo "XXXXXXXXXXXXX==" | openssl enc -base64 -d | openssl enc -des3 -k mysalt -d)
curl -k -XPOST -d '[email protected]&passwd=$logmetPassword&space=myspace&organization=muOrg' https://mywebsite/login

The problem is, it takes $logmetPassword as it is witout substituting the value. I've tried many options:

curl -k -XPOST -d '[email protected]&passwd=${logmetPassword}&  space=myspace&organization=muOrg' https://mywebsite/login
curl -k -XPOST -d '[email protected]&passwd="{$logmetPassword}"&space=myspace&organization=muOrg' https://mywebsite/login
curl -k -XPOST -d '[email protected]&passwd=\"{$logmetPassword}\"&space=myspace&organization=muOrg' https://mywebsite/log

Any suggestions?

Upvotes: 0

Views: 62

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753695

If you want $logmetPassword substituted, you must enclose the argument (or that bit of the argument) in double quotes. The shell does not expand any metacharacters inside single quotes.

You could use either of these:

curl -k -XPOST -d "[email protected]&passwd=${logmetPassword}&space=myspace&organization=muOrg" https://mywebsite/login
curl -k -XPOST -d '[email protected]&passwd='"{$logmetPassword}"'&space=myspace&organization=muOrg' https://mywebsite/login

The first encloses everything in double quotes; the second only encloses the password in double quotes. On the whole, I'd probably use the second, but the first is safe for the strings shown.

Upvotes: 2

Related Questions