help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] trap when expected return value may be non-zero?


From: adrelanos
Subject: Re: [Help-bash] trap when expected return value may be non-zero?
Date: Thu, 02 May 2013 19:14:40 +0000

Matthew Cengia:
> I'd do it like this:
> 
> | address@hidden:tmp$ trap "echo error" ERR INT TERM
> | address@hidden:tmp$ false
> | error
> | address@hidden:tmp$ false || { ret=$?; true; }
> | address@hidden:tmp$ echo $ret
> | 1
> 
> So as you can see, false exits with status '1', and therefore the trap
> is hit. However, if you OR the result with something that is guaranteed
> to succeed (e.g. true or ':'), grabbing a copy of the return code of
> the first command before calling 'true', you can avoid hitting the trap.

That looks nice!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]