[GLLUG] bash PS1 commands...
Matt Graham
danceswithcrows@usa.net
Thu, 15 May 2003 19:44:28 -0400
Several folks asked about customizing the prompt when using bash. This
is at least one way to do it:
export PS1='\[\033[01;32m\]\h:\[\033[01;34m\]\w\$ \[\033[00m\]'
...looks ugly. Let's dissect it.
\[\033[01;32m\]
The \[ and \] are delimiters which tell bash that whatever's enclosed in
them is a nonprinting sequence of characters. The \033[01;32m is an
escape code sequence that says "set the foreground color to light
green". "man console_codes" for info on all the escape sequences you
can use.
\h:
"\h" gets expanded to the hostname of the machine you're currently on.
":" just prints a : .
\[\033[01;34m\]
Another escape sequence that sets the foreground color to blue.
\w\$
\w expands to the current working directory. \$ expands to a $ sign if
you're a normal user, and a # sign if you're root.
\[\033[00m\]
A final escape code sequence that sets the foreground and backgrouns
colors to their defaults. If you left this off, whatever you typed at
the prompt would be blue! Don't leave this off if you've decided to
mess with colors.
Other things you can embed into PS1 include:
\A current time
\u current username
\d current date
\W current working directory (short form)
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html for more than you
ever wanted to know about this subject.
--
Something unpleasant is coming when men are anxious to tell the
truth. --Benjamin Disraeli
There is no Darkness in Eternity/But only Light too dim for us to see