I am running an echo command in bash and I am seeing some unexpected results.
When running:
echo "{
"outputs": {
"result": "[{\"directory\":\"mydir\",\"somekey\":\"somevalue\"}]"
},
"outcome": "success",
"conclusion": "success"
}"
The output is:
{
outputs: {
result: ["directory":"mydir"]
},
outcome: success,
conclusion: success
} {
outputs: {
result: ["somekey":"somevalue"]
},
outcome: success,
conclusion: success
}
I understand that the result key is not valid json but why does the output seem to iterate of the values in the result array and output the objects? What causes this in the bash or echo command side?
If I remove the double quotes on from the beginning and the end of the result array, it outputs the entire json blob as expected but curious why I get the other output when json is malformed.
What you see is called brace expansion. At its most simple, it looks like
If the braces are embedded in a string, the entire string gets repeated:
Importantly, when the braces are quoted, the expansion doesn't happen:
In your case,
prefixisaisbisand
suffixis