Wednesday, February 17, 2021

Bash Script to Print All Unicode Characters to the Terminal

Here's a bash script that loops through 4-digit codes and prints the Unicode character associated with the code. Make sure your terminal supports Unicode characters
#!/bin/sh
export BASHOPTS=xpg_echo
from=0000 to=ffff
from=$(printf '%d' "0x$from") to=$(printf '%d' "0x$to")
while test "$from" -le "$to"; do
num=$(printf '%04x' "$from")
bash -c "echo -n \"\u$num\""
from=$((from+1))
done
view raw gistfile1.txt hosted with ❤ by GitHub

References

https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
https://stackoverflow.com/questions/5517500/generating-hex-numbers-of-a-certain-range

No comments: