In your case, there is a special quoting syntax used, namely $'...'
and $"..."
. It looks like this syntax came from the Korn shell to Zsh and Bash, and is now in POSIX (see for example the "expand sequences" line in http://mywiki.wooledge.org/Bashism).
This syntax is not mentioned in the answers to Differences between doublequotes " ", singlequotes ' ' and backticks ´ ´ on commandline?.
Details on this syntax can be found in the bash(1) manpage:
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. Backslash escape sequences, if present, are
decoded as follows:
\a alert (bell)
\b backspace
\e
\E an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\" double quote
\nnn the eight-bit character whose value is the octal value
nnn (one to three digits)
\xHH the eight-bit character whose value is the hexadecimal
value HH (one or two hex digits)
\uHHHH the Unicode (ISO/IEC 10646) character whose value is
the hexadecimal value HHHH (one to four hex digits)
\UHHHHHHHH
the Unicode (ISO/IEC 10646) character whose value is the
hexadecimal value HHHHHHHH (one to eight hex digits)
\cx a control-x character
The expanded result is single-quoted, as if the dollar sign had not
been present.
A double-quoted string preceded by a dollar sign ($"string") will
cause the string to be translated according to the current locale. If
the current locale is C or POSIX, the dollar sign is ignored. If the
string is translated and replaced, the replacement is double-quoted.
This also means that a variable will be expanded in $"..."
, but not in $'...'
. Please compare:
$ echo 'I am using\t$SHELL.\n'
I am using\t$SHELL.\n
$ echo $'I am using\t$SHELL.\n'
I am using $SHELL.
$ echo "I am using\t$SHELL.\n"
I am using\t/bin/bash.\n
$ echo $"I am using\t$SHELL.\n"
I am using\t/bin/bash.\n
In the first example, neither the $SHELL
variable nor the backslash escapes are expanded. In the second example, the backslash examples are expanded, but not the variable. The third and fourth examples give identical results: Only the variable is expanded.
The form $'...'
can be useful to assign contents with meta-characters like \t
or \n
to variables. I could not find an application for the form $"..."
, though.
"..."
vs.'...'
vs.\
...``, this question is about$"..."
vs.$'...'
(note the dollar sign before the quotes). – Dubu Mar 12 '14 at 12:25