Bash – Print a character having a codepoint

bashcharacter encodingunicode

I have a list of codepoints like 0x13000, 0x1300A.
I have to print the corresponding Unicode characters from bash.
I've already tried to do it with other commands that I've found searching in the forum (In bash, how can I convert a Unicode Codepoint [0-9A-F] into a printable character?), but they didn't work.

I've tried

echo -ne 'x13000/x130FF/' | iconv -f utf-16be

and, using perl on the terminal

perl -C -e 'print chr 0x130F0' 

Best Answer

This does it in two steps:

$ printf "$(printf '\\U%08x' 0x13000)\n"
?

If you are unable to see the rendered glyph (character image), here is a fixed image:

enter image description here

The two steps are: - The first formats the codepoint number (0x13000) in 8 hexadecimal digits with \U in its front. - The second use the bash builtin printf capacity to print Unicode characters.

The output will be adapted to the locale used.

In utf8 locales like en_US.utf8 and with a font that could present the correct glyph, the output character will be correctly presented in the console.

In this system, the full noto-font package was installed. It contains very nice text fonts, well hinted, and as a plus it also contains glyphs for many many languages, including the "Noto Sans Egyptian Hieroglyphs" font.

This will print all the character list:

$ printf "$(printf '\\U%08x' 778{24..34})"; echo
???????????

the value range is just the hexadecimal values in decimal:

$ printf '%d\n' 0x13000 0x1300A
77824
77834