bug-bash
[Top][All Lists]
Advanced

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

Re: Logical expression works does not work as expected


From: Greg Wooledge
Subject: Re: Logical expression works does not work as expected
Date: Sat, 28 Dec 2024 16:06:00 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Sat, Dec 28, 2024 at 15:23:41 -0500, Lawrence Velázquez wrote:
> On Fri, Dec 27, 2024, at 6:47 PM, Greg Wooledge wrote:
> > You might have been raised on some other language where the && and ||
> > operators have different precedence.  In the shell language, they have
> > the same precedence.
> 
> However, the && and || arithmetic operators do have C-like precedence.
> 
>       $ echo "$((1 && 1 || 0 && 0))"
>       1
>       $ echo "$(( ((1 && 1) || 0) && 0 ))"
>       0
> 
> So be aware of context.

Yes.  Safety and consistency are profane words in shell designs.

Every feature is designed independently of every other feature, and
the goal is to trip you up as many times as possible.



reply via email to

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