Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
@Giles Thanks for the formatting tweaks! –  Ed Brannin Sep 14 '12 at 12:54

3 Answers 3

up vote 37 down vote accepted

There are two different things going on here, both documented in the bash manual

$'

Dollar-sign single quote is a special form of quoting:

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.

$"

Dollar-sign double-quote is for localization:

Locale translation

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.

share|improve this answer

When a string is expanded inside of $'', the escape sequences are interpreted. From the 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.

An easy example is the \n escape sequence for a newline:

$ echo 'foo\n'
foo\n
$ echo $'foo\n'
foo

$ 

Note: You may get different results in other shells as echo may interpret escape sequences without providing options.

share|improve this answer
6  
There is no mention of $"...", as per the question. –  Peter.O Sep 14 '12 at 7:05

You're misinterpreting the manual. You'll only see an effect when a $-quoted string is inside a ${parameter} expansion.

$ echo "${v:-'ab\ncd'}"
'ab\ncd'
$ echo "${v:-$'ab\ncd'}"
ab
cd

Source and further reading: https://lists.gnu.org/archive/html/bug-bash/2005-10/msg00017.html

share|improve this answer
5  
This doesn't answer the question: $"…" is something different. –  Gilles Sep 13 '12 at 23:55
2  
Sorry, but your answer is wrong: there is no need to use ${} expansion to make use of ANSI quoting. Check for yourself: echo $'ab\ncd' –  rozcietrzewiacz Sep 14 '12 at 7:04
1  
I think this answer was trying to explain extquote incorrectly instead of what the question was asking. –  jw013 Sep 14 '12 at 14:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.