[Gllug] show non-zero exit code in bash

salsaman salsaman at xs4all.nl
Tue Dec 27 18:07:00 UTC 2005


Dean Wilson wrote:

>On Mon, Dec 26, 2005 at 11:08:20PM +0000, Greater London Linux User Group wrote:
>  
>
>>I don't think you'll achieve this by setting anything to do with the
>>prompt. $? stays untouched until another command is executed, ignoring,
>>quite rightly IMO, commands run by bash itself.
>>    
>>
>
>After playing with it some more I've come to agree.
>
>  
>
>>What you essentially want to do is follow each command with:
>>     || echo "Oops! Buggered by a '$?'."
>>    
>>
>
>Except if the command already has a && or a || then there's a good chance
>it'll screw up.
>
>  
>
>>(Of course you could make it more elegant by creating an alias, say 'e',
>>so you could simply say '||e')
>>    
>>
>
>You're not lazy enough :)
>
>  
>
>>You could always hack the bash source to add this functionality if it's
>>not already there :)
>>    
>>
>
>Um. Well. Er. I don't want it that badly ;)
>
>  Dean
>  
>



I was playing around with this idea over Christmas, here is what I came 
up with:

_() { $@; echo $?; }


then after that, you can run any command with _<space> before it, e.g.:

_ false
_ true

and the exit code will be shown.

Gabriel.

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list