2

This is a question out of sheer curiosity:

I have a custom PS1 setting in bash that is just the current directory, followed by a lowercase lambda (λ), e.g. . I accidentally used cat with a binary file, cancelled the output, and subsequently had the λ turn into two Japanese characters ホサ for the rest of the session. When pasting in this character from somewhere else, it was also displayed as these two Japanese characters.

Now my question is, how did the output of this binary file change how bash interprets Unicode characters?

1 Answer 1

5

my question is, how did the output of this binary file change how bash interprets Unicode characters?

Standard Unix terminals support ANSI/VT-100 commands which can control the cursors, the colors, and the fonts. When you type an binary file to the screen, it is likely that some of the binary characters will accidentally match such control codes and set properties of your terminal.

To return your terminal to its default state, run:

reset

Examples of VT-100 control sequences

If you would like the text on your teminal to blink, type:

echo -e '\E[5m'

If you want to switch the display to reverse video, type:

echo -e '\E[7m'

As a more complex example, consider the make command which can produce a lot of output. To make it easier to spot the important things, you may want to highlight ERR in reverse video while displaying WARNING in bold. The following code adds VT-100 controls sequences in to the output of make to obtain this highlighting on the terminal:

make 2>&1 | sed -e 's/.*\bERR.*/\x1b[7m&\x1b[0m/i' -e 's/.*\bWARN.*/\x1b[1m&\x1b[0m/i'

The above adds control sequences intentionally. When a binary file is typed to the screen, there is no telling what VT-100 control sequences will be accidentally activated.

2
  • I assumed it had something to do with control sequences, but I can't seem to find any control sequence which changes the representation of Unicode characters, also not in the listing you've linked. Nov 7, 2014 at 23:48
  • 1
    There are many commands to change character sets. As an example, ESC ( 0 and ESC ) 0 set "Special Graphics Character Set". More on control codes to set character sets can be found here. I suspect that it would take quite some digging through font definitions and configuration files to determine which one of these sequences results in your system displaying a lambda as a Japanese character.
    – John1024
    Nov 8, 2014 at 0:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .