I have an array of unicode points that i want to be able to convert back into characters and store it inside a variable as a string. In the example below it's just the "Hello World!" code point array but I could have any unicode number (up to 16 bits).
array=( 72 101 108 108 111 32 87 111 114 108 100 33 )
I checked:
- How to convert \uXXXX unicode to UTF-8 using console tools in *nix
- How can I convert all UTF8 Unicode characters in a string to their relevant Codepoints using bash/shell/zsh?
and other online resources but I still can't figure out how to do this. I tried things like:
temp=
for c in ${array[@]}; do
temp+="\U$c"
done
printf %b "$temp"
I also saw bash has a new feature that allows you to do either echo -e '\Uxxxxx'
or $'\Uxxx'
but in my case it doesn't work since even if i iterate over the array and store each code point inside a variable i
, the single quotes would prevent bash from expanding it in this case: echo $'\U$i'
, i even tried echo "$'\U$i'"
.
I'm utterly clueless on how to do this with pure bash in a simple way..