Bash – What does a bash sequence ‘\033[999D’ mean and where is it explained

bashterminal

I have come across bash sequences such as \033[999D and \033[2K\r which are used to do some manipulation on a printout on a terminal. But what do these sequences mean? Where can I find a list/summary on the web to help me find out the meaning of these sequences?

Best Answer

See this link http://www.termsys.demon.co.uk/vtansi.htm. As Anthon says, \033 is the C-style octal code for an escape character. The [999D moves the cursor back 999 columns, presumably a brute force way of getting to the start of the line. [2K erases the current line. \r is a carriage return which will move the cursor back to the start of the current line and is a C-style escape sequence rather than a terminal control sequence.

Update

As other people have pointed out, these control sequences are nothing to do bash itself but rather the terminal device/emulator the text appears on. Once upon a time it was common for these sequences to be interpreted by a completely different piece of hardware. Originally, each one would respond to completely different sets of codes. To deal with this the termcap and terminfo libraries where used to write code compatible with multiple terminals. The tput command is an interface to the terminfo library (termcap support can also be compiled in) and is a more robust way to create compatible sequences.

That said, there is also the ANSI X3.64 or ECMA-48 standard. Any modern terminal implementation will use this. terminfo and termcap are still relevant as the implementation may be incomplete or include non standard extensions, however for most purposes it is safe to assume that common ANSI sequences will work.

The xterm FAQ provides some interesting information on differences between modern terminal emulators (many just try to emulate xterm itself) and how xterm sequences relate to the VT100 terminals mentioned in the above link. It also provides a definitive list of xterm control sequences.

Also commonly used of course is the Linux console, a definitive list of control sequences for it can be found in man console_codes, along with a comparison to xterm.

Related Question