bash - 理解 bash 中的 $' ' 引号

标签 bash syntax quotes

至少在 bash 模式替换中经常使用以下引号:$' ' 例如 ${arr[@]/%/$'\n\n\n'} 在每个数组“arr”项之后打印三个换行符。这些是某种特殊的报价吗?他们怎么称呼?除了 bash 模式替换之外,它们还用在什么地方?

最佳答案

ANSI-C 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.


例如:

$'hello\nworld'

您将得到 11 个字符,中间有 换行符


echo -e 'hello\nworld'
echo   $'hello\nworld'

他们给你相同的结果。

关于bash - 理解 bash 中的 $' ' 引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13427163/

相关文章:

mysql - MySQL 中何时使用单引号、双引号和反引号

python - 当字符串周围的引号不匹配时,为什么 Python 不会给出任何错误?

linux - curl 或读取每一行 url 文本文件,然后将每一行输出到标记为连续数字的单独文件 - 1 2 3 等

linux - Cron 作业是否会覆盖自身

php - php中的 "or"是什么意思?

Java反射(reflect)Class.forName失败

用于获取从特定字符串开始的用户的 Linux 批处理命令

bash - 使用docker exec将带有转义字符的参数传递给脚本

javascript - 没有 TypeError 的深度 Javascript 检查是否未定义

php - 将 PHP 代码写入文件