If I use the bash shell cli and run some program which doesn't return immediately, then I input some letters (basically typing the next command before noticing the previous didn't finish) and the input always looks something like this (especially when using arrow up and down keys:)

]]A^ or ]]B^

And I wonder, is this kind of premature input 'harmful' in anyway, or what does the returned string mean?

  • 1
    This is not specific to bash, I would remove that tag.
    – Didi Kohen
    Oct 11, 2012 at 18:51

2 Answers 2


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.

  • 1
    From what I understood from the question, the case here was during the execution of another command and not in the silver time between process exit and before bash restored the terminal settings. I did upvote your answer though, since it's explaining the case in detail, unlike my answer which is the absolute minimum needed to answer.
    – Didi Kohen
    Oct 11, 2012 at 20:14
  • @DavidKohen I think you are right about the original question. I adjusted my answer a bit to account for when the command is still running.
    – jw013
    Oct 11, 2012 at 20:28

These strings are the raw representation of the special characters you typed (like home, end, arrows, tab etc...).
Their harmful effect is controlled by the command you are running, if it is receiving input from the terminal, these characters will be part of it's input.
If it does not take input from the terminal, it shouldn't have any adverse effects on any of the Unix flavors I know of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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