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