简体   繁体   English

bash中的$'\\ n'是什么意思?

[英]What does $'\n' mean in bash?

An answer in this stackoverflow question In a Linux shell how can I process each line of a multiline string? 这个stackoverflow问题的答案在Linux shell中,如何处理多行字符串的每一行? mentions that $'\\n' is a special syntax "is not available in every shell". 提到$'\\n'是一种特殊语法,“并非在每个shell中都可用”。

I wonder what does the syntax mean? 我想知道语法是什么意思吗?

Thank you. 谢谢。

See the QUOTING section of the bash man page: 请参见bash手册页的QUOTING部分:

   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.

This syntax is not part of the standard Unix Bourne shell. 该语法不是标准Unix Bourne shell的一部分。 It may be specific to bash, although I haven't looked around to see if other shells support it. 它可能特定于bash,尽管我没有四处看看是否有其他shell支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM