你如何在 Bash 中回显 4 位 Unicode 字符? [英] How do you echo a 4-digit Unicode character in Bash?

查看:17
本文介绍了你如何在 Bash 中回显 4 位 Unicode 字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Unicode 骷髅和交叉骨添加到我的 shell 提示中(特别是 'SKULL AND CROSSBONES' (U+2620)),但我无法弄清楚魔法咒语使 echo 吐出它,或任何其他 4 位 Unicode 字符.两位数的很容易.例如,echo -e "x55", .

I'd like to add the Unicode skull and crossbones to my shell prompt (specifically the 'SKULL AND CROSSBONES' (U+2620)), but I can't figure out the magic incantation to make echo spit it, or any other, 4-digit Unicode character. Two-digit one's are easy. For example, echo -e "x55", .

除了下面的答案之外,还应该注意的是,很明显,您的终端需要支持 Unicode 才能使输出符合您的预期.gnome-terminal 在这方面做得很好,但它不一定默认打开.

In addition to the answers below it should be noted that, obviously, your terminal needs to support Unicode for the output to be what you expect. gnome-terminal does a good job of this, but it isn't necessarily turned on by default.

在 macOS 的终端应用程序中转到首选项->编码并选择 Unicode (UTF-8).

On macOS's Terminal app Go to Preferences-> Encodings and choose Unicode (UTF-8).

推荐答案

在 UTF-8 中,它实际上是 6 位(或 3 个字节).

In UTF-8 it's actually 6 digits (or 3 bytes).

$ printf 'xE2x98xA0'
☠

要检查控制台如何编码,请使用 hexdump:

To check how it's encoded by the console, use hexdump:

$ printf ☠ | hexdump
0000000 98e2 00a0                              
0000003

这篇关于你如何在 Bash 中回显 4 位 Unicode 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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