Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm wondering why Shift + Arrow Key result in one of the A, B, C or D letters.

Why not other letters? Why any letter at all?

share|improve this question
Intriguing :D My bet? Has to do with text based gaming :D – Rinzwind Apr 23 '13 at 17:29
Just an observation: in tty Shift + Arrow Keys doesn't do anything. – Radu Rădeanu Apr 23 '13 at 17:33
@Rinzwind: :))) – Radu Rădeanu Apr 23 '13 at 17:36
I asked this question on Unix/Linux Stack Exchange. There are some useful answers. Maybe you want to look at them.… – yfklon Apr 30 '13 at 5:35
up vote 25 down vote accepted

Terminal emulators such as gnome-terminal ("Terminal" in Ubuntu) but also xterm and urxvt are named "emulators" because they reproduce the behavior of older terminals which were the only display of a computer. Such terminals communicated with the computer with a text-based protocol and were initially designed to receive only text. Quickly, more control was needed: how to erase a line? Use colors? Or change the cursor position?

VT-100 terminal Source: The Art of Unix Usability - Command-Line Interfaces

Escape sequences were designed for every terminal to do such things. They are named escape because they start with the ASCII escape code: 33. There's no way to print such a character directly, which makes it a good fit for such sequences. When we still want to display this characted, ^[[ is used, and this is what I'll use in my explanations.

When the terminal received ^[[A, it did not mean "print ^[[A", but "the user pressed the up-arrow key". "A" here is totally arbitrary: it just happens to be the letter everybody agreed on, because that's what the DEC VT-52 and its successor the popular VT-100 terminal used.

DEC VT-52 Maintenance Manuel 1976

Source: DEC VT-52 Maintenance Manual 1976

This is still the way terminal emulators work today: depending on the $TERM variable, a database named terminfo is responsible for saying what codes should be sent to the shell (bash, sh, zsh...), which is then responsible for understanding them and react to them.

Now, the code for Shift + up happens to be ^[[1;2A: the terminal emulator sends this code to the shell, which tries to interpret ^[[1;2 but does not display anything because it doesn't know about that escape sequence. But A is left and displayed.

share|improve this answer
Wow, interesting. Now all those ^[[A make sense when I click the arrow keys while a process is running on the terminal. – Dan Apr 24 '13 at 7:25
You may hit CTRL-v just before you hit SHIFT-UpArrow to 'view' the escape sequences in raw form. Unless you have changed the defaults, ESC should appear on your terminal screen as ^[ – arielf Apr 26 '13 at 21:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.