when I use the write
program to send messages, how can I use UTF-8 chars?
I send:
write user2
Ehilà! Com'è?
But receiver gets:
Message from user1@samehost on pts/1 at 21:08 ...
EhilM-CM- ! Com'M-CM-(?
The machine is the same and LANG
in konsole is already en_US.UTF-8
.
Best Answer
It appears
write
is interpreting the high bit as ‘meta-’ (Meta+key or Esc key). A quick look at the source code (functionwr_fputs()
inwrite.c
) confirms this: control characters are shown as^X
, characters with the high bit set are shown asM-X
. Locale settings, terminals and encodings have nothing to do with it, I'm afraid.write
is just 7-bit.Now, I'm a Unicode freak, but this makes a perverted sort of sense.
write
just opens the target TTY and writes to it (there's no magic involved). There's no easy way to get the character encoding understood by the process controlling the remote TTY. And even if there were, not all encodings are convertible to all other encodings. And without conversion, transmitting a message in KOI8-R to an ISO-8859-1 console would fail miserably. Sincewrite
takes the simplistic, 70s approach, this is what we get.