Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dollar character before double quotes in Bash

Tags:

bash

I recently read some bash code, echo $"asdf", what is $ for?

What is the difference between $"asdf" and just "asdf"?

like image 886
nfpyfzyf Avatar asked May 21 '13 08:05

nfpyfzyf


People also ask

Why is there a dollar sign in bash?

That dollar sign means: we're in the system shell, i.e the program that you're put into as soon as you open the Terminal app. The dollar sign is often the symbol used to signify where you can begin typing in commands (you should see a blinking cursor there).

How do I escape the dollar sign in bash?

Escape characters: It preserves the literal value of the character followed by this symbol. Normally, $ symbol is used in bash to represent any defined variable. But if you use escape in front of $ symbol then the meaning of $ will be ignored and it will print the variable name instead of the value.

How do you escape a double quote in bash?

' appearing in double quotes is escaped using a backslash. The backslash preceding the ' ! ' is not removed. The special parameters ' * ' and ' @ ' have special meaning when in double quotes (see Shell Parameter Expansion).

What is dollar at in bash?

This is due to some users finding the unique Bash characters such as $@, $_, and $1 confusing. Beginning with the $@ Bash parameter, it is being used to extend into the positional arguments. Each parameter extends into something like a distinct word whenever expanding happens within double-quotes.


1 Answers

As documented in the bash manual, it is used for localization:

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.

like image 51
dogbane Avatar answered Oct 23 '22 01:10

dogbane