I have come across bash sequences such as
\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?
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.
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
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.
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.
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
\033 is the escape character, and those sequence are not bash specific but interpreted by the terminal (software or hardware (via network or serial line)) in which the (bash) program runs. There are many such sequences.
What each does, depends on the terminal for which it is dependent, and might also depend on any previous sequence altering the state of the terminal.
These are often used to set colors in the bash prompt, but I did not find your particular examples on that page.
'\033[999D' is funny. Some terminals implement fewer of the escape sequences, so this might be needed if none of '\033[1G', '\033[1;1H', '\033[1;1f', or '\r' behave as they should, but who uses a thousand-column text display? These sequences have a man page in Linux: console_codes(4). bjh21 has a detailed list of all the codes. Depending on which program parses '\033', the more clear substitution '\e' might be available.
It is really not intended that these be used directly — the correct way to issue terminal control commands is with an abstraction layer such as ncurses — but they function just as well from string literals.
you can search for "033 term escape list" or "033 tput" and see http://wiki.bash-hackers.org/scripting/terminalcodes for more info before someone answering ;]