Citação de man bash
, seção QUOTING :
A non-quoted backslash (
\
) is the escape character. It preserves the literal value of the next character that follows, with the exception of<newline>
. If a\<newline>
pair appears, and the backslash is not itself quoted, the\<newline>
is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).
Isso permite que você interrompa sequências de comandos / comandos muito longos (canalizações e transformações de saída, etc.) em scripts em várias linhas para facilitar a leitura.
Para conseguir tratar a nova linha como você espera, apenas coloque o valor (e qualquer uso posterior da variável) entre aspas.
$ A="B
> C"
$ echo "$A"
B
C
Da mesma seção:
Enclosing characters in single quotes preserves the literal value of each character within the quotes. ...
Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, ',
\
, and, when history expansion is enabled, !. The characters $ and ' retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: $, ', ",\
, or .