Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I found a couple of documents listing some of the capabilities of the bash prompt with non-printing characters (e.g. \E[33;44m to print yellow text on blue background), but everywhere I look, I only find very specific examples, and no real explanation of those special characters, or a complete list of everything that is possible with those characters.

Sometimes, the examples use a \033[ prefix, and sometimes it's \E[, is there a difference between both?

So far, I know the following is possible :

Use color : \E[33;44m
Move the cursor to a specific place (10th line, 20th column) : \033[10;20H
Hide the cursor : \E[?25l
Show the cursor : \E[?25h

Are there other magic combinations? Where can I find a full list of those special characters and how to use them?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Sometimes, the examples use a \033[ prefix, and sometimes it's \E[, is there a difference between both?

First layer: The \ is an "escape character" in C and other programming languages. \033 and \x1B are C-style octal and hexadecimal escapes for the ASCII control character ESC (hexadecimal byte 0x1B). \e and \E are part of C too and also mean the same ESC character, but are not as common.

Whichever of the above you use, the same ESC is going to be inserted, but \e is shorter to type than \033.

Are there other magic combinations? Where can I find a full list of those special characters and how to use them?

Second layer: Similarly, the ASCII ESC is a prefix for ANSI escape codes used by the VT100 terminal and its descendants. The codes available aren't up to bash, but to the specific terminal emulator you're using. Probably all support the codes defined in ECMA-48, but it's only a small subset.

The Xterm control sequences page has an extensive list, but you'll want to look for documentation for whatever you're using, be it gnome-terminal, Konsole, rxvt or whatever. Some are specific to Linux console (tty).

share|improve this answer
    
Most graphical terminals emulators, with the exception of rxvt, are attempting to emulate Xterm (and set $TERM accordingly). –  grawity Mar 25 '11 at 20:27
1  
@grawity: True, but there are in fact differences between them, often in the details of things like setting terminal/tab titles, and each of them has a handful of things the others don't (or do differently). Which is why I called the XTerm sequences a good start. –  geekosaur Mar 25 '11 at 20:33
    
linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-6.html : This place seems to refer to ANSI Escape Sequences, which would imply there is some sort of standard. Is what is listed there pretty much supported on all (modern) terminal emulators, and is that list complete? –  Fred Mar 25 '11 at 20:34
1  
@Fred: ANSI X3.64 is a standard for terminal escape sequences; most terminal emulators implement a superset of it. You can do quite a bit with it, but a fair amount of interesting stuff is outside the standard. –  geekosaur Mar 25 '11 at 20:41
    
Excellent team work there. The original post + the edit make for a perfect answer. Thanks. –  Fred Mar 25 '11 at 20:46
show 2 more comments

Your Answer

 
discard

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.