[Gllug] show non-zero exit code in bash
Russell Howe
rhowe at siksai.co.uk
Fri Dec 23 15:07:01 UTC 2005
On Fri, Dec 23, 2005 at 02:42:27PM +0000, Dean Wilson 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.
>
> I'd like to do the same thing in bash but I've hit a stumbling block. The
> following PROMPT_COMMAND does most of what I want:
>
> PROMPT_COMMAND='ret=$?; if [ "$ret" -ne "0" ];then echo exit code: $ret;fi'
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'
--
Russell Howe | Why be just another cog in the machine,
rhowe at siksai.co.uk | when you can be the spanner in the works?
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list