0

I have a bash script that echo's and performs some text replacement using sed like this

var=$(<file)

The file looks something like this

{
  "name": "John",
  "address": "Somewhere"
}

When I echo "$var" (formatting is retained) it looks fine. When I use curl -d '@test_file_with_json' the server accepts it as well however when I do curl -d '$var' it gets rejects and the API tells me the json is invalid.

At first I thought it was because of the single quotes but I tried -d '"$var"', -d "$var" and various other combinations but I cannot get it to work.

I'm sure this is something very obvious but how can I get the data inside the var to post? The actual content is very long (couple of hundred lines) so putting it all directly in the curl command is not practical.

sjaak
  • 524
  • 1
  • 4
  • 16
  • You need to pass to `curl` the **content** of your variable, not the string `$` `v` `a` `r`. You have to write `curl -d "$var"`. – user1934428 Jul 01 '21 at 06:20

0 Answers0