Search code examples
shellvariable-expansion

Variable expansion inside single quotes


I am quite new to shell scripting.

I have the following script:

out="FAILURE"
curl -X POST -d 'json={"json":"message"}' http://localhost:8888/json.tail.test

I want to replace "message" with the $out's value. I tried different ways but could not get that done. Can someone please suggest me?


Solution

  • Do this:

    out="FAILURE"
    curl -X POST -d 'json={"json":"'$out'"}' http://localhost:8888/json.tail.test
    

    Basically, enclose everything except $out inside single quotes. Single quotes protect double quotes but suppress the expansion of variables like $out.