Artificial intelligent assistant

Interpolate within single quotes I have the following: COMMENT="A random comment" TEXT_JSON='{"person" : "Jim","comment" : "$COMMENT"}' echo "$TEXT_JSON" | jq . This prints { "person": "Jim", "comment": "$COMMENT" } which is not what I want. How can I interpolate the string here?

You cannot interpolate inside single quotes.

You can put the string in double quotes, then escape the literal double quotes:


COMMENT="A random comment"
TEXT_JSON="{\"person\" : \"Jim\",\"comment\" : \"$COMMENT\"}"
echo $TEXT_JSON | jq .
{
"person": "Jim",
"comment": "A random comment"
}


Or alternatively you can keep the single quotes so you don't have to escape anything, but end the single quotes before the variable, then use double quotes for the variable, then single quotes for the last part of the string:


TEXT_JSON='{"person" : "Jim","comment" : "'"$COMMENT"'"}'

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2dd85d29ba78e5b8942d5c254184c9d5