Results 1 to 2 of 2
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.
Code:
#!/bin/bash
KKK="…hkjh'"
echo ${KKK}
printf "%b\n" "${KKK}"
...
- 12-23-2011 #1Just Joined!
- Join Date
- Nov 2004
- Posts
- 5
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.
and what I get isCode:#!/bin/bash KKK="…hkjh'" echo ${KKK} printf "%b\n" "${KKK}" printf -v GGG "%q" "${KKK}" printf "%b\n" "${GGG}"
which is not what I was expecting (the leading $ and single quote wrappers).Code:…hkjh' …hkjh' $'…hkjh\''
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.
- 12-23-2011 #2Just Joined!
- Join Date
- Nov 2004
- Posts
- 5
So my hack is adding:
which yields:Code:GGG=$(printf "%b\n" "${GGG}") if [[ "${GGG:0:1}" = "\$" ]]; then LL=${#GGG} GGG="${GGG:2:($LL-3)}" fi echo $GGG
Code:…hkjh\'


Reply With Quote