I recently read some bash code, echo $"asdf"
, what is $
for?
What is the difference between $"asdf"
and just "asdf"
?
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).
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.
' 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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With