有一天突发奇想,怎么在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.
-
In [5]: chr(8364)
-
Out[5]: '?'
-
-
In [6]: chr(0x20ac)
-
Out[6]: '?'
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. 参考网站:
阅读(2520) | 评论(0) | 转发(0) |