此stackoverflow问题In a Linux shell how can I process each line of a multiline string?中的答案提到$'\n'
是一种特殊语法“并非在每个shell中都可用。”
我想知道语法是什么意思?
谢谢。
答案 0 :(得分:5)
请参阅QUOTING
手册页的bash
部分:
Words of the form $'string' are treated specially. The word expands to
string, with backslash-escaped characters replaced as specified by the
ANSI C standard. Backslash escape sequences, if present, are decoded as
follows:
...
\n new line
...
The expanded result is single-quoted, as if the dollar sign had not been
present.
此语法不是标准Unix Bourne shell的一部分。它可能是特定的bash,虽然我没有环顾四周看看其他shell是否支持它。