打印UNI code字 [英] Print unicode character
问题描述
在bash,你可以使用的printf
十六进制codeS
\\用十六进制值HH(1至2位)XHH字节
\\ Joey:嗯统一code(ISO / IEC 10646)字符的十六进制值HHHH(4位)
例如
$ printf的'\\ X26'
&安培;
然而,由于预期的Uni code例如不打印
$ printf的'\\ u0026'
\\ u0026
我的Bash版本
$回声$ BASH_VERSION
4.1.10(4)-release
什么版本的庆典
的回声$ BASH_VERSION
或的bash --version
)?单向code转义庆典
4.2的工作,但不是3.2.48。我怀疑在庆典
加入支持4.0。更新:我可以证实它不会在庆典
4.1.2工作。这个功能似乎在被加入庆典
4.2
更新2:从发行说明对于bash 4.2 :
Ð。
$...
,回声
和的printf
理解为\\ uXXXX
和\\ UXXXXXXXX
逃生
序列。
块引用>With Bash, you can use
printf
with hex codes\xHH byte with hexadecimal value HH (1 to 2 digits) \uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
example
$ printf '\x26' &
However the Unicode example does not print as expected
$ printf '\u0026' \u0026
My Bash version
$ echo $BASH_VERSION 4.1.10(4)-release
解决方案What version of
bash
are you using (echo $BASH_VERSION
orbash --version
)? The Unicode escapes work inbash
4.2, but not 3.2.48. I suspect support was added inbash
4.0.Update: I can confirm it does not work in
bash
4.1.2. This functionality appears to have been added inbash
4.2.Update 2: From the release notes for bash 4.2:
d.
$'...'
,echo
, andprintf
understand\uXXXX
and\UXXXXXXXX
escape sequences.
这篇关于打印UNI code字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!