Unquoted backslashes remove special meaning from the following
character (with an exception for a backslash+newline pair).
In the first example the first backslash quotes the second.
echo \\n
\\ -> \
n -> n
echo \n <- final command
In the second example the first backslash quotes the second and the
third backslash quotes the 'n'
echo \\\n
\\ -> \
\n -> n
echo \n <- final command
> but when
> they are put into subshell the output is different?
In the third and fourth examples the backslashes are being processed
twice -- once by the parent shell (outside the `...`) and again by the
subshell (inside the `...`).
When processing a back-quoted command substitution the parent shell
will only treat a backslash as escaping the next character if the next
character is a back-quote, a backslash or a dollar sign. If the
command substitution is within double quotes a backslash also escapes
a double quote.
In the third example the parent shell treats the first backslash as
quoting the second. As the third backslash is not followed by one
of [`\$] it is treated as a literal character. The subshell then
processes the command within back-quotes using unquoted backslash
rules.
echo `echo \\\n`
\\ -> \ }
\ -> \ } parent processing
n -> n }
echo \\n <- subshell command
\\ -> \ } subshell processing
n -> n }
echo \n <- command executed by subshell
\n <- captured output
echo \n <- final command
In the fourth example the parent shell treats the first backslash as
escaping the second. The subshell then processes the backslashes and
treats the '\' as escaping the 'n'.
echo `echo \\n`
\\ -> \ } parent processing
n -> n }
echo \n <- subshell command
\n -> n } subshell processing
echo n <- command executed by subshell
n <- captured output
echo n <- final command
You may be expecting your shell's echo to behave like echo -e.