0

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?

codeforester
  • 39,467
  • 16
  • 112
  • 140
Mahbub Rahman
  • 1,295
  • 1
  • 24
  • 44

2 Answers2

1

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.

codeforester
  • 39,467
  • 16
  • 112
  • 140
0

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

Hum4n01d
  • 1,312
  • 3
  • 15
  • 30
  • That won't expand the `$OUT` part. Also, the expansion of `$OUT` needs to be inside double quotes as per OP's requirement. Please see my answer below. – codeforester Jan 31 '17 at 03:06