Reputation: 463
I am trying to use a bash variable to store json.
testConfig=",{
\"Classification\": \"mapred-site\",
\"Properties\": {
\"mapreduce.map.java.opts\": \"-Xmx2270m\",
\"mapreduce.map.memory.mb\": \"9712\"
}
}"
echo $testConfig Output: ,{
If I give it in a single line it works. But i would like to store values in my variable in a clean format.
I tried using cat >>ECHO That didn't work either
Any help is appreciated as to how I can store this in order to get the output in an expected format. Thanks.
Upvotes: 2
Views: 2367
Reputation: 157947
You may use a here doc as described here:
read -r -d '' testConfig <<'EOF'
{
"Classification": "mapred-site",
"Properties": {
"mapreduce.map.java.opts": "-Xmx2270m",
"mapreduce.map.memory.mb": "9712"
}
}
EOF
# Just to demonstrate that it works ...
echo "$testConfig" | jq .
Doing so you can avoid quoting.
Upvotes: 2