Some keys on your keyboard don't correspond to actual characters. For example, A corresponds to the character a
but the Up and F1 keys do not have their own dedicated characters. When those special keys are pressed, instead of getting a single character corresponding to the key, the terminal translates the keypress to a special sequence of multiple characters that typically begin with the escape character (usually displayed as ^[
). For example, Up usually generates the sequence ^[[A
(that's 3 characters from one key: escape, [
, and A
).
The reason you normally do not see ^[[A
is because most console applications are smart enough to translate the special sequences into useful commands instead of just echoing it to the console. To do this, they turn off the terminal's built-in echoing and do their own lower-level processing. For example, when bash
sees ^[[A
,¹ it realizes that means you pressed Up and rather than echoing ^[[A
back, it does a whole bunch of stuff to delete whatever you've typed so far, fetch the previous command saved in history, and print that instead.
If you see ^[[A
when you press Up, that typically means that terminal echoing is turned on and the foreground process (the one in control of the terminal) is not doing any of the special processing mentioned above. This may be because the application simply ignores the terminal (like most non-interactive commands). Note that typically, the shell puts the terminal into canonical mode and turns on echoing before running a foreground process, and restores its own settings once it regains control of the terminal after the command exits.
The echoing seems fairly harmless. Just remember that if the running command doesn't read from the terminal, the characters you generated via the keyboard will probably end up in bash
's input queue, so be careful what you type as they probably will be interpreted as normal commands once bash
resumes reading from the terminal.
¹ This is actually an oversimplification. Since the specific sequence can vary by terminal type, there are typically multiple layers of abstraction libraries in between a console application and the terminal itself. For example, bash
uses the readline
library to do most of its input.