Shell里面打印utf 8字符

 

有一天突发奇想,怎么在shell里面打印utf-8字符呢?搜索下了发现不少办法。

  1. 使用echo 和printf
    例如打印欧元符号,首先通过网页
    https://www.w3schools.com/charsets/ref_utf_currency.asp
    可以查到欧元的dec是8364, hex是20ac.

     root@kali:/usr/local/src/py/project_dirs# printf '\U20AC\n'
     €
     root@kali:/usr/local/src/py/project_dirs# printf '\u20ac\n'
     €
     root@kali:/usr/local/src/py/project_dirs# echo -e '\u20ac'
     €
     root@kali:/usr/local/src/py/project_dirs# echo -e '\U20AC'
     €
    
  2. 使用python

     root@kali:~# ipython3
     Python 3.6.6 (default, Jun 27 2018, 14:44:17) 
     Type "copyright", "credits" or "license" for more information.
    
     IPython 5.5.0 -- An enhanced Interactive Python.
     ?         -> Introduction and overview of IPython's features.
     %quickref -> Quick reference.
     help      -> Python's own help system.
     object?   -> Details about 'object', use 'object??' for extra details.
    
     In [1]: chr(0x20ac)
     Out[1]: '€'
    
     In [2]: chr(8364)
     Out[2]: '€'
    
  3. 使用unicode.
    在kali linux上安装unicode 很简单.

     apt-get install unicode
    
     root@kali:/usr/local/src/py/project_dirs# unicode 20ac
     U+20AC EURO SIGN
     UTF-8: e2 82 ac UTF-16BE: 20ac Decimal: € Octal: \020254
     €
     Category: Sc (Symbol, Currency)
     Unicode block: 20A0..20CF; Currency Symbols
     Bidi: ET (European Number Terminator)
    
     root@kali:/usr/local/src/py/project_dirs# unicode -d 8364
     U+20AC EURO SIGN
     UTF-8: e2 82 ac UTF-16BE: 20ac Decimal: € Octal: \020254
     €
     Category: Sc (Symbol, Currency)
     Unicode block: 20A0..20CF; Currency Symbols
     Bidi: ET (European Number Terminator)
    
  4. 参考网站: https://www.w3schools.com/charsets/ref_html_utf8.asp
    http://whatisunicode.com