7

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

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

codeforester
  • 39,467
  • 16
  • 112
  • 140
nfpyfzyf
  • 2,891
  • 6
  • 26
  • 30
  • 1
    Possible duplicate of [What are the special dollar sign shell variables?](https://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables) and [What does it mean to have a $“dollarsign-prefixed string” in a script?](https://unix.stackexchange.com/questions/48106/what-does-it-mean-to-have-a-dollarsign-prefixed-string-in-a-script) – Andre Figueiredo Aug 10 '17 at 16:57

1 Answers1

12

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.

dogbane
  • 266,786
  • 75
  • 396
  • 414
  • 2
    Could you give an example demonstrating when this actually has an influence on the outcome? – Alfe May 21 '13 at 08:33
  • 1
    wow I just learned something new today, it's a good day (+1) :) – ant May 21 '13 at 08:41
  • @Alfe, the setup is quite complex. It uses gettext in the background. This link to the Bash manual makes it easy to see the next section, too, where some more details are explained. – Palec May 26 '23 at 09:12
  • @Palec There is no “next” section after the chapter the link points to. Just a “previous” and an “up”. (And the up→next is “comments”.) – Alfe May 30 '23 at 10:24
  • 1
    ‍♂️ Sorry, forgot to post the link, @Alfe. Here it is: https://www.gnu.org/software/bash/manual/bash.html#Locale-Translation – Palec May 30 '23 at 11:17
  • Oh, yeah. That’s really complex. I didn’t go through it all but thanks for the pointer to how it *would* be used! :-) – Alfe May 31 '23 at 13:05