打印UNI code字 [英] Print unicode character

查看:133
本文介绍了打印UNI code字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 or bash --version)? The Unicode escapes work in bash 4.2, but not 3.2.48. I suspect support was added in bash 4.0.

Update: I can confirm it does not work in bash 4.1.2. This functionality appears to have been added in bash 4.2.

Update 2: From the release notes for bash 4.2:

d. $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.

这篇关于打印UNI code字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆