字符串封装像$“Hello World”。

时间:2014-03-14 20:17:18

标签: bash

我只是在Centos 6.5框上阅读/etc/init.d/httpd,并注意到所有字符串似乎都被引用为$"Hello World."。我之前从未见过这种语法,而且我似乎无法通过谷歌发现任何内容。

摘录:

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"

这是什么交易?

1 个答案:

答案 0 :(得分:6)

来自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.