Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
These are ascii/ansi escape code control sequences. They are used for coloring and formatting text in a terminal environment. All escape sequences start with a '\033' escape code, of which '\e' is a shortcut in bash. After that comes a code for color or other text manipulation. In this example, '\e[32m' is the code for green text, and \e[0m' is the code for clearing the formatting at the end of the string.
Bash furthermore uses '\[' and '\]' for enclosing these escape sequences in the PS1 prompt. Without them the terminal can do strange things, especially when it comes to line-wrapping.
Finally, I believe the '\e]0;' sequence is for setting the xterm title formatting, but I'm not 100% sure about that. Every example I've seen follows the xterm string with a \007
Edit: Aah, '\a' is the bash equivilent to the '\007' bell code. So yes, the first part of the sequence is the xterm title setting.
Edit2: Look at 'man bash' for a detailed list of PS1 sequences. And this page gives you a multitude of examples on how to use them in PS1.
Last edited by David the H.; 06-14-2009 at 09:02 AM.
Well, to tell the truth, I've only recently discovered them myself, and only just learned how to use them in PS1 a few days ago. It seems that the exact phrasing of the sequences depends on the environment you use, but it's not so hard once you know them.
Let's break this example up to make it clearer what each part is doing.
Code:
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$
# The first part sets the xterm title (usually shows in the titlebar of the window).
\[ -Starts a sequence of escapes.
\e]0; -Starts the xterm title prompt expression.
\w -Display the current working directory.
\a -Equal to \007 (system bell). In this case used to end the xterm title prompt.
\] -End escape sequence.
# The second part sets the actual PS1 prompt
\n -Start with a newline.
\[ -Start another sequence of escapes.
\e[32m -Sets the color to green.
\] -End escape sequence.
\u@\h -User at host name. This and the \w below are the visible parts of the prompt.
\[ -Begin another escape sequence.
\e[33m -Set color to red.
\] -End escape sequence.
\w -Display working directory in prompt.
\[ -Begin another sequence.
\e[0m -Reset escape formatting to default.
\] -End sequence.
\n -Another newline.
\$ -The final command line prompt character.
I hope this makes it all clearer to you.
Last edited by David the H.; 06-14-2009 at 02:50 PM.
Reason: Made some minor edits
I notice the \a that is closing the "\[\e]0;\w\a\]\n" part of PS1 (which is an \007 and a bell) is necessary for this command to write into the window header.
\[ -Starts a sequence of escapes.
\e]0; -Starts the xterm title prompt expression.
\w -Display the current working directory.
\a -Equal to \007 (system bell).
In this case used to end the xterm title prompt.
\] -End escape sequence.
=====================
Noticed something interesting:
Generally, it seems Linux is case sensitive for path/filenames.
However, a "cd /Bin" does work on my cygwin; and does navigate to the correct /bin folder. But the prompt now shows that directory as though it were "/Bin", but is not...???
I cannot find a doc reference that discusses this use of the bell character.
Truthfully, I've never seen one either. All I know is that every example I've ever seen ends the sequence with it, so I must assume it's mandatory. I'd love to see some clear confirmation of it though.
And thanks for finding the tldp page. That's a great reference.
Quote:
However, a "cd /Bin" does work on my cygwin; and does navigate to the correct /bin folder. But the prompt now shows that directory as though it were "/Bin", but is not...???
Is this a bug or a feature?
I don't know anything about cygwin, but considering that it runs on the case-insensitive OS, I can only imagine that it's been deliberately set up that way. It could be that they've simply defined Bin as a symlink to bin. If I create a symlink to a directory on my system and cd into it, my prompt also displays the symlink name instead of the real name.
Last edited by David the H.; 06-17-2009 at 01:46 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.