[Techtalk] shell scripting - modifying your prompt

Andrea Landaker qirien at icecavern.net
Mon Feb 10 20:26:14 EST 2003

On Monday 10 February 2003 05:59 pm, Maria Blackmore wrote:
> you may also like to know that the exit code from the last command run
> usually ends up in $?.  eg:

If you end up using this frequently, you can modify your bash prompt to 
include this variable.  ${PIPESTATUS[@]} will show you the status of 
everything run in a pipeline, which can be slightly more useful than $? 
sometimes (since $? is really just ${PIPESTATUS[0]}).

In your .bashrc, put something like:

export PS1="[ \${PIPESTATUS[@]} \u@\h \w ]$ "

(you *need* the backslash in front of ${PIPESTATUS} because you want it to 
evaluate every time your prompt comes up, not just once when you're setting 
your prompt)

This is also where you can put in nifty colors if you want; eg, for your 
PIPESTATUS to show up in magenta you can put:

export PS1="[ \[\e[35m\]\${PIPESTATUS[@]} \[\e[0m\]\u@\h \w ]$ "

(here, the \[\e[35m\] says "start using magenta" and \[\e[0m\] says "start 
using whatever the normal color is")

who has a very colorful bash prompt

More information about the Techtalk mailing list