Mahbub Rahman
Mahbub Rahman

Reputation: 1343

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?

Upvotes: 0

Views: 769

Answers (2)

codeforester
codeforester

Reputation: 42999

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.

Upvotes: 1

Hum4n01d
Hum4n01d

Reputation: 1370

Try this:

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

You just need to literally replace "message" with $OUT

Upvotes: 0

Related Questions