Friday, 23 December 2011

bash printf %q weirdness and UTF-8

bash printf %q weirdness and UTF-8

I'm trying to get nice escaped strings via bash. The script works fine so long as there aren't high ASCII (UTF-8) characters.


echo ${KKK}
printf "%b\n" "${KKK}"
printf -v GGG "%q" "${KKK}"
printf "%b\n" "${GGG}"

and what I get is


which is not what I was expecting (the leading $ and single quote wrappers).

My shell is LANG=en_US.UTF-8 and it seems to handle the display of UTF-8 fine.

The … is UTF code pt +2026 or 0xE280A6.

No comments:

Post a Comment