Re: $PROMPT_COMMAND (WAS: Re: Using $PROMPT_COMMAND to beep depending on success/failure)

Tim Chase <[email protected]>
Newsgroups gmane.linux.redhat.blinux.general
Message-ID <[email protected]>
> On 4/22/2016 2:09 PM, Lars wrote:
> Do any of you know of a way to get a number as the first cell(s)
> in the prompt indicating the error code of the previous command?

Yes, just include "$?" in your $PS1 variable.  I have something like:

  export PS1='{$?}\u@\h:\w\$ '

in my ~/.bashrc to give me a prompt like

  {0}tim@netbook:/etc$

where the "{0}" at the beginning shows the exit/error code from the
previously-run program.

I include the username ("\u"), short hostname ("\h"), and working
directory ("\w") mostly because I manage a number of machines, so it
helps me make sure I'm not issuing commands on some remote box I
admin.

-tim
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.