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 10:16:18 +0100
User-agent: Mutt/1.5.6i

On Fri, Jun 29, 2007 at 10:21:01AM +0200, Robert Millan [ackstorm] wrote:
[...]
> > >   There's bitwise AND and bitwise OR, and logical AND and logical OR, but
> > >   for XOR there's only the bitwise version.  Would be nice if the logical
> > >   XOR would also be present (^^).
> > 
> > (!a) != (!b)
> > 
> > should work acceptably for the situations such an operator would be used.
> 
> I'm not sure what you mean.  The following:
> 
>       (true && ! false) || (false && ! true)
>       echo $?
> 
> works, whereas the following:
> 
>       (! true) != (! false)
>       echo $?
> 
> shows syntax error.
> 
> Is there any way to avoid redundancy in the shell script that needs this?  The
> code in question is already quite complex, so adding this redundancy makes it
> less readable.
[...]

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.

-- 
St├ęphane




reply via email to

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