My system language is not Japanese, but my user language/encoding is. Using shell things in terminal emulators 'directly' works okay, but it seems that 'behind the scene' stuff does not.
保存 = Save for example.
This gets displayed correctly when I use X stuff 'directly' (as in, I open a terminal emulator or GUI program and mess with it directly) But running stuff in the background (using dmenu, in the xmonad WM ) it turns out that what gets fed into scripts is not something I can string compare to, but something like this:
保存...
gets turned into
'344円277円235円345円255円230円...'
How do I generate this myself? I only got the escaped value string from this by putting a copy paste thing into the script.
I'm fine with doing a pre-pass that translates such an escaped value string into a 'proper' one that then gets case matched later.
I would simply like to generate such an escaped value string myself without the roundabout hack.
1 Answer 1
With the zsh
shell, with:
string="保存 = Save for example.
Also including newlines,
'quotes and \backslashes"
() {
local LC_ALL=C
quoted=${${(qqqq)1}#'$'}
} "$string"
printf '%s\n' $quoted
Gives:
'344円277円235円345円255円230円 = Save for example.\nAlso including newlines,\n\'quotes and \\backslashes'
If it's only the bytes over 0x80 you want to convert to \ooo
:
printf %s "$string" |
perl -l -0777 -pe 's/[\x80-\xff]/sprintf "\\%o", ord$&/ge'
would give (from any Bourne-like shell):
344円277円235円345円255円230円 = Save for example.
Also including newlines,
'quotes and \backslashes
You must log in to answer this question.
Explore related questions
See similar questions with these tags.
\
or'
themselves?