【问题标题】:understanding $' ' quotes in bash理解 bash 中的 $' ' 引号
【发布时间】:2012-11-05 19:15:39
【问题描述】:

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

【问题讨论】:

    标签: bash syntax quotes


    【解决方案1】:

    ANSI-C Quoting

    $'string' 形式的单词被特殊处理。单词扩展为字符串,并按照 ANSI C 标准的规定替换反斜杠转义字符。


    例如:

    $'hello\nworld'
    

    你会得到11 个字符,中间有换行符。


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

    他们给你同样的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 2016-09-12
      • 2011-11-17
      相关资源
      最近更新 更多