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: Jeffrey Walton
Subject: Re: confusing syntax error using <= within [[ ]]
Date: Mon, 6 Oct 2025 10:26:24 -0400

On Mon, Oct 6, 2025 at 8:08 AM w f <wm_fry@yahoo.com> wrote:
>
> For 5.2.37(1)-release ...
>
> The example is somewhat contrived but its essence is pulled from an actual 
> script I'm working on.

You should run your script through Shellcheck.  It will help find
syntactical issues.

> a=1 b=1 c=10 d=11
> 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?
>
> If I remove the space between "<=" and "$d" it works fine.
> If I replace the "<=" with ">=" (and keep the space after the "="), it fails.
> Any other operator ("<", ">","==","!=") with a spaces works fine.

Jeff



reply via email to

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