VALUE=<<PERSON
some data
PERSON
echo "$VALUE"
No output.
A here-document is a redirection, you can't redirect into a variable.
When the command line is parsed, redirections are handled in a separate step from variable assignments. Your command is therefore equivalent to (note the space)
VALUE= <<PERSON
some data
PERSON
That is, it assigns an empty string to your variable, then redirects standard input from the here-string into the command (but there is no command, so nothing happens).
Note that
<<PERSON
some data
PERSON
is valid, as is
<somefile
It's just that there is no command whose standard input stream can be set to contain the data, so it's just lost.
This would work though:
VALUE=$(cat <<PERSON
some data
PERSON
)
Here, the command that receives the here-document is cat
, and it copies it to its standard output. This is then what is assigned to the variable by means of the command substitution.
In your case, you could instead use
python -m json.tool <<END_JSON
JSON data here
END_JSON
without taking the extra step of storing the data in a variable.
It may also be worth while to look into tools like jo
to create the JSON data with the correct encoding:
For example:
jo type=account customer_id=1234 customer_email=jim@gmail.com random_data="some^Wdata"
... where ^W
is a literal Ctrl+W character, would output
{"type":"account","customer_id":1234,"customer_email":"jim@gmail.com","random_data":"some\u0017data"}
So the command in the question could be written
jo type=account customer_id=1234 customer_email=jim@gmail.com |
python -m json.tool
echo $VALUE
without... | jq
would be informative. – Nick T Apr 11 '18 at 18:27