理解bash中的$''引用

Mar*_*tin 5 syntax bash quotes

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

kev*_*kev 10

ANSI-C引用

表格的字$'string'是特别对待的.单词扩展为字符串,替换为ANSI C标准指定的反斜杠转义字符.


例如:

$'hello\nworld'
Run Code Online (Sandbox Code Playgroud)

你会在中间获得11换行符的角色.


echo -e 'hello\nworld'
echo   $'hello\nworld'
Run Code Online (Sandbox Code Playgroud)

他们给你相同的结果.