help-bash
[Top][All Lists]
Advanced

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

Re: confusing syntax error using <= within [[ ]]


From: Greg Wooledge
Subject: Re: confusing syntax error using <= within [[ ]]
Date: Mon, 6 Oct 2025 10:00:41 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Mon, Oct 06, 2025 at 09:25:30 -0400, Lawrence Velázquez wrote:
> On Mon, Oct 6, 2025, at 8:26 AM, Greg Wooledge wrote:
> > On Mon, Oct 06, 2025 at 06:17:46 +0000, w f wrote:
> >> if [[ (-n $a && $c <= $d) || (-n $b && $c == $d) ]] ; then echo ok ; else 
> >> echo no ; fi
> >> -bash: expected ')'
> >> -bash: syntax error near `$d)'
> >> 
> >> Why does this give a syntax error?
> >
> > Because you need spaces around ( and ) in that command.
> 
> This doesn't seem to be the case for "[[":
> 
>       $ LC_ALL=C bash -c '[[ (x > y) ]]'; echo "$?"
>       1

Ah, then the help text is incomplete.

And... I can't find parentheses documented in the defintion of [[ in the
man page, nor in the CONDITIONAL EXPRESSIONS section that it refers to.

The only place I find parentheses mentioned in the man page is under
the definition of test and [ which says:

              ( expr )
                     Returns the value of expr.  This may be used  to  override
                     the normal precedence of operators.

The mention of ( EXPRESSION ) in the "help [[" text seems to be the
only place it's documented, and that shows spaces.  Just like the ( expr )
in [ shows spaces, and they're definitely needed in that case (though
I would strongly advise against trying to use them in test or [ in the
first place, just as I would advise against using binary -a or -o).



reply via email to

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