[Gllug] show non-zero exit code in bash

Dean Wilson dwilson at unixdaemon.net
Sat Dec 24 11:43:20 UTC 2005


On Fri, Dec 23, 2005 at 03:07:01PM +0000, Russell Howe wrote:
> > I have shell envy. One of my co-workers uses zsh and has a nifty feature
> > that shows you the exit code of any command that doesn't return a 0.

> You need to track state. Something like this:
> PROMPT_COMMAND='ret=$?; if [ "x$SHOWNRETCODE" != "xyes" -a "$ret" -ne "0" ];then echo exit code: $ret; SHOWNRETCODE=yes; fi'

That's closer but it's still not right. The problem with that one is
that it only shows an error code once. No matter which error code comes
afterwards.

For example:

$ sdfsdfs
-bash: sdfsdfs: command not found
exit code: 127

$ ls fooo
ls: fooo: No such file or directory

No exit code even though it's now 1.

I've been trying to reset the value of $? to 0 between commands so it only
shows on errors, and not just return presses but I've had no luck yet.

  Dean
-- 
Dean Wilson             http://www.unixdaemon.net
Profanity is the one language all programmers understand
  --- Anon
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list