Hash symbols (#) turned into pound symbols (£) after catting a binary

The terminal accepts and executes a bunch of different character sequences as control commands. For example, all cursor movement is done using those. Some of the codes make permanent changes, like setting colors, or telling the terminal to use an alternate character set. Executables and other binary files can well contain bytes that represent those commands, so dumping binary files to the terminal can have annoying side effects. See e.g. here for some of the control codes.

The historical background to this is that originally, terminals were rather dumb devices with a screen and a keyboard, and they connected to the actual computer via a serial port. Before that, they were printers with keyboards. There wasn't much of a protocol to separate data bytes from command bytes, so commands were given to the terminal "inline". (Or rather, the escape codes and control characters were the protocol.) One might assume that if the system was devised today, there would be clearer separation between data and commands.

Instead of just closing the terminal window or killing the emulator, you can use the reset command, which sends a similar command (or several) to reset the terminal back to sane defaults.

I don't know what exactly would cause the hash to pound change. (But @Random832 does, see their answer.) I'm more familiar with the "alternate character set", which can change all characters into line-drawing glyphs. Even if that happens, input from the keyboard usually goes through unchanged, so writing resetEnter still works even if the characters display as garbage or not at all. (Compared to your prompt being turned into a bunch of lines, you only got a minor effect.)


For the record, to answer why this happened and how it could have been fixed without closing the terminal (and if reset failed):

Many terminals support, as a feature of the VT220 terminals they are emulating, a number of national replacement character sets based on ISO 646 and ISO 2022. In particular, it is very common for some reason, even if the others aren't supported, for them to support the British character set, which has the pound currency symbol in the same position where ASCII has the number sign.

So, when you printed a binary file to the terminal, it by some coincidence output the sequence ESC ( A [or perhaps ESC ) A and ^N] to the terminal. This can be undone manually by printing the sequence that sets it to the normal status:

printf '\e(B\e)0\x0f'

Close the terminal and open a new one.

Tags:

Terminal