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).