来自 bash 的 printf unicode 7 个字符

来自 bash 的 printf unicode 7 个字符

我在 Ubuntu 20.04 上。我想打印我尝试了 bash 中的符号,printf "\u1F5E0"但没有成功。这应该有效吗?还是我缺少字体包?请告诉我该怎么办。

答案1

你可以试试这个(用大写字母)?

printf "\U1f5e0"或者echo -e "\U1f5e0"

这应该取决于您的 bash 区域设置(LANG=en_US.UTF-8LANG=fr_FR.UTF-8),可以在您的 .bashrc 配置文件或脚本中设置。

该页面内容如下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 se‐
       quences, 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
              \?     question mark
              \nnn   the eight-bit character whose value is the octal value nnn (one to three octal 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.

相关内容