How to interpret string variable with two dollar sign for curl on shell script?

40 Views Asked by At

I have a problem on running curl command on shell script. I have a string variable with two dollar sign character, show as below example:

local auth="$3xLxLBcsKv$zY59kBuIpKeG4q1526phJ9"

I need pass this variable to curl command. Like below is my write but not work:

curl --connect-timeout 2 -H 'Extender-Auth: $auth' https://192.168.5.1/1/

But the writing is wrong on shell script. Can someone help me how to modify the writing make it work on shell script?

Thank for your help!

Make curl can work with above option and value.

1

There are 1 best solutions below

2
dash-o On

With double quote - bash will try to perform variable substitution in the enclosed string:

local auth="$3xLxLBcsKv$zY59kBuIpKeG4q1526phJ9"

Will try to expand "$3", and "$zY59kBuIpKeG4q1526phJ". Most likely second is empty, and first may be anything.

Try using the single quote, which does not perform substitution:

local auth='$3xLxLBcsKv$zY59kBuIpKeG4q1526phJ9'

curl --connect-timeout 2 -H "Extender-Auth: $auth" https://192.168.5.1/1/