The $
in the beginning of the string in :
echo $'Hello World\nThis is a new line'
causes escape sequences to be interpreted.
Bash reference manual [ says ]
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.
..
..
The expanded result is single-quoted, as if the dollar sign had not been present.
But
echo $"Hello World\nThis is a new line"
is completely different. This [ article ] on locale specific translation says :
A double-quoted string preceded by a dollar sign (‘$’) 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.
Note: IIRC both $'string'
and $"string"
may not find support among different shells. Not only do people from other shells look at them with curiosity but also they debate on whether this could be avoided for script portability.
"weak quote"
and'strong quote'
are different from$'C String'
and$"I18N String"
. – DopeGhoti Aug 18 '16 at 04:30