I just saw this in an init script:
echo $"Stopping Apache"
What is that dollar-sign for?
My research so far:
I found this in the bash manual:
extquote
If set,
$'string'
and$"string"
quoting is performed within${parameter}
expansions enclosed in double quotes. This option is enabled by default.
...but I'm not finding any difference between strings with and without the $
prefix:
$ echo "I am in $PWD"
I am in /var/shared/home/southworth/qed
$ echo $"I am in $PWD"
I am in /var/shared/home/southworth/qed
$ echo $"I am in ${PWD}"
I am in /var/shared/home/southworth/qed
$ echo "I am in ${PWD}"
I am in /var/shared/home/southworth/qed
$ echo 'I am in ${PWD}'
I am in ${PWD}
$ echo $'I am in ${PWD}'
I am in ${PWD}
$ echo $'I am in $PWD'
I am in $PWD
$''
when you can just use""
? I'm sure there's a reason and for my understanding it would be good to know. – Sridhar Sarnobat Jan 20 '21 at 21:39""
does not interpret that much. Try$'\x31'
vs."\x31"
. – domen May 17 '21 at 14:45"$variable\n"
will result in the contents of the variable followed by a newline, whereas$'$variable\n'
will result in $variable followed by a newline. So, if you want to avoid escaping dollar signs and double quotes in a string and still be able to escape single quotes (for example if you are passing a complex command to a specific shell from within a bash script), then$''
is the way to go. – UrsineRaven Mar 28 '22 at 16:46$"..."
is useful? I found the docs, too, but I do not really understand what they say. What does it mean to translate a string according to the current locale? I know what locale is, BTW. – Palec May 25 '23 at 20:03