How do you echo a 4-digit Unicode character in Bash? How do you echo a 4-digit Unicode character in Bash? bash bash

How do you echo a 4-digit Unicode character in Bash?


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

$ printf '\xE2\x98\xA0'

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

$ printf ☠ | hexdump0000000 98e2 00a0                              0000003


% echo -e '\u2620'     # \u takes four hexadecimal digits☠% echo -e '\U0001f602' # \U takes eight hexadecimal digits😂

This works in Zsh (I've checked version 4.3) and in Bash 4.2 or newer.


So long as your text-editors can cope with Unicode (presumably encoded in UTF-8) you can enter the Unicode code-point directly.

For instance, in the Vim text-editor you would enter insert mode and press Ctrl + V + U and then the code-point number as a 4-digit hexadecimal number (pad with zeros if necessary). So you would type Ctrl + V + U 2 6 2 0. See: What is the easiest way to insert Unicode characters into a document?

At a terminal running Bash you would type CTRL+SHIFT+U and type in the hexadecimal code-point of the character you want. During input your cursor should show an underlined u. The first non-digit you type ends input, and renders the character. So you could be able to print U+2620 in Bash using the following:

echo CTRL+SHIFT+U2620ENTERENTER

(The first enter ends Unicode input, and the second runs the echo command.)

Credit: Ask Ubuntu SE