bug-bash
[Top][All Lists]
Advanced

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

Re: logical XOR


From: Stephane Chazelas
Subject: Re: logical XOR
Date: Fri, 29 Jun 2007 14:20:46 +0100
User-agent: Mutt/1.5.6i

On Fri, Jun 29, 2007 at 12:08:22PM +0200, Robert Millan [ackstorm] wrote:
> On Fri, Jun 29, 2007 at 10:16:18AM +0100, Stephane Chazelas wrote:
> > 
> > Do you mean that for instance, you'd like a third command to be
> > executed if either but not both of two commands succeed?
> > 
> > cmd1; a=$?
> > cmd2; b=$?
> > (( !a != !b )) && cmd3
> > 
> > should do.
> 
> Thank you, that works.  Although I think ^^ would be more intuitive.  Let me
> know if you want a patch for that.
[...]

You could do something like:

xor() {
  previous_status=$?
  "$@"
  return "$((!$previous_status == !$?))"
}

cmd1; xor cmd2 && cmd3

-- 
Stéphane




reply via email to

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