linux - $'\n' 在 bash 中是什么意思?

标签 linux bash shell unix

这个 stackoverflow 问题的答案 In a Linux shell how can I process each line of a multiline string?提到 $'\n' 是一种特殊语法“并非在每个 shell 中都可用”。

我想知道语法是什么意思?

谢谢。

最佳答案

请参阅 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.

此语法不是标准 Unix Bourne shell 的一部分。它可能是 bash 特有的,尽管我没有四处查看其他 shell 是否支持它。

关于linux - $'\n' 在 bash 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13925879/

相关文章:

bash 脚本中的 Linux sed

linux - 如何仅提取从 diff 命令返回的文件名?

linux - 文件监控 Bash 脚本

linux - 将静态库链接到共享库

PHP 5.3.2 和 Zend Framework session

python - 将变量从 Python 传递到 Bash

Linux shell 脚本到 tar.gzip 日志文件超过 1 个月按月分组

linux - shell如何为awk生成输入

linux - 检测当前连接是否使用 NetworkManager 进行计量

linux - 将 wget 与 OpenID 登录结合使用