Martin
Martin

Reputation: 1197

understanding $' ' quotes in bash

At least in bash pattern substitution following quotes are often used: $' ' For example ${arr[@]/%/$'\n\n\n'} prints three newline characters after each array "arr" item. Are those some sort of special quotes? How are they called? Where are they used besides bash pattern substitution?

Upvotes: 5

Views: 139

Answers (1)

kev
kev

Reputation: 161954

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.


For example:

$'hello\nworld'

You'll get 11 characters with newline in the middle.


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

They give you the same result.

Upvotes: 10

Related Questions