I have written them following shell script to view what the Unicode characters look like on my terminal.
#!/bin/bash
X=0
while [ $X -lt 65536 ]; do
HEX=`bc <<< "obase=16; $X"`
HEX="0x${HEX}"
UCODENAME=`printf "%0*x\n" 4 $HEX`
UCODECHAR=`printf "\u%0*x\n" 4 $HEX`
echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
X=$((X + 1))
done
When I run the script I receive the following output:
print_unicode: line 9: printf: missing unicode digit for \u
Unicode 0188 = ƈ
The second line is exactly what I am looking for.
I did try using strictly printf in an attempt to eliminate the error.
#!/bin/bash
X=0
while [ $X -lt 65536 ]; do
HEX=`bc <<< "obase=16; $X"`
HEX="0x${HEX}"
printf 'Unicode %0*x = \u%0*x\n' 4 $HEX 4 $HEX
X=$((X + 1))
done
I get the following output:
print_unicode: line 8: printf: missing unicode digit for \u
Unicode 037f = \u037f
The second line is not what I am looking for, and I still get the same error message.
How do I fix this error?
Bonus: What is a more elegant solution for this?