Birchlabs Birchlabs - 1 month ago 18
Bash Question

Where did my backslashes go?

I have a JSON structure, escaped inside another JSON structure, escaped inside another JSON structure.

cat
shows the file contents just fine:

Answer

The variable is being set to the correct value. You are either using dash, not bash, or your bash shell has the xpg_echo option set. The zsh built-in echo, though, behaves according to the POSIX specification, which replaces certain escaped characters. Try using printf instead:

$ printf '%s\n' "$X"
{
  "payload": "{\"data\":\"{\\\"nested\\\":1}\"}"
}