From https://unix.stackexchange.com/a/378549/674
tmp=${string//"$separator"/$'\2'}
What does $
in $'\2'
mean?
Is $'\2'
a parameter expansion?
Thanks.
From https://unix.stackexchange.com/a/378549/674
tmp=${string//"$separator"/$'\2'}
What does $
in $'\2'
mean?
Is $'\2'
a parameter expansion?
Thanks.
This is ANSI-C Quoting:
Words of the form
$'string'
are treated specially. The word expands tostring
, with backslash-escaped characters replaced as specified by the ANSI C standard.
$'\2'
is expanded to the eight-bit character whose value is the octal value 2. In the answer you refer to, this character is used as a field separator.
$\2
specified instead? – Tim Aug 01 '17 at 14:24$
introduces the string in Bash, it has no special meaning in C; if you wanted to store the string$\2
in C, you’d just escape the backslash,$\\2
. – Stephen Kitt Aug 01 '17 at 14:280x2
? Is there a similar metacharacter in C to$
in Bash? – Tim Aug 01 '17 at 14:30$
-style metacharacter, backslashes are interpreted in this way in all C strings: you’d just write"\2"
. – Stephen Kitt Aug 01 '17 at 14:42