3

I was just reading through the /etc/init.d/httpd on a Centos 6.5 box and noticed that all of the strings seem to be quoted like $"Hello World.". I've never seen this syntax before, and I can't seem to turn up anything via google.

Excerpt:

if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
    RETVAL=6
    echo $"not reloading due to configuration syntax error"
    failure $"not reloading $httpd due to configuration syntax error"

What's the deal?

Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • @tripleee marking as duplicate *three years* later? – Sammitch Aug 21 '17 at 23:53
  • Collecting answers in one place rather than sprinkle the site with duplicates is a long-term maintenance process. Ideally, somebody should have noticed the duplication earlier, but that doesn't mean it's not useful to mark it up now. – tripleee Aug 22 '17 at 03:44

1 Answers1

6

From man bash

   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.  Backslash escape sequences, if present, are decoded
   as follows:
          \a     alert (bell)
          \b     backspace
          \e
          \E     an escape character
          \f     form feed
          \n     new line
          \r     carriage return
          \t     horizontal tab
          \v     vertical tab
          \\     backslash
          \'     single quote
          \"     double quote
          \nnn   the eight-bit character whose value is  the  octal  value
                 nnn (one to three digits)
          \xHH   the  eight-bit  character  whose value is the hexadecimal
                 value HH (one or two hex digits)
          \uHHHH the Unicode (ISO/IEC 10646) character whose value is  the
                 hexadecimal value HHHH (one to four hex digits)
          \UHHHHHHHH
                 the  Unicode (ISO/IEC 10646) character whose value is the
                 hexadecimal value HHHHHHHH (one to eight hex digits)
          \cx    a control-x character

   The expanded result is single-quoted, as if the  dollar  sign  had  not
   been present.

   A double-quoted string preceded by a dollar sign ($"string") 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.
Jakub Kotowski
  • 7,411
  • 29
  • 38
  • That means that the string could be translated depending on the locale being used? (if translation available, of course) – jimm-cl Mar 14 '14 at 20:25
  • Thanks! Poking around via other channels also turned up a bit of documentation on how it's implemented: http://tldp.org/LDP/abs/html/localization.html – Sammitch Mar 14 '14 at 20:30
  • an article about it here: http://www.cyberciti.biz/faq/bash-localization-with-echo-command/ – Jakub Kotowski Mar 14 '14 at 20:31