Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 793
Martin Avatar asked Nov 17 '12 02:11

Martin


1 Answers

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.

like image 196
kev Avatar answered Sep 28 '22 09:09

kev