tags:

views:

2313

answers:

3

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. 2 digit one's are easy echo -e "\x55", for example.

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. Go to Terminal-> Set Character Encoding and choose Unicode (UTF-8).

+3  A: 

Just put "☠" in your shell script. In the correct locale and on a Unicode-Enabled console it'll print just fine:

$ echo ☠
☠
$

An ugly "workaround" would be to output the UTF-8 sequence, but that also depends on the encoding used:

$ echo -e "\xE2\x98\xA0"
☠
$
Joachim Sauer
+5  A: 

In UTF-8 it's actually 6 digit (or 3 byte).

$ echo -e "\xE2\x98\xA0"
☠

:-)

To check how it's encoded by you console, you can use hexdump.

echo -n ☠ | hexdump
vartec
+1  A: 
% echo -e '\u2620'
☠
% $SHELL --version
zsh 4.3.4 (i386-redhat-linux-gnu)
Juliano
that just spits out \u2620 when I do it.
masukomi
For me too. Which shell are you using, Juliano?
Joachim Sauer
Sorry, forgot to say that I use zsh.
Juliano
Also works with zsh on Mac OS 10.5. Nice!
Craig S