On 2/23/23 3:26 AM, Qingsheng Huang wrote:
Here shows the behavious of empty conditional expressions:

------------------------------------------------------------------------
infinite:~# [[ ]]
-bash: syntax error near unexpected token `]]'
infinite:~# [[ ]]
infinite:~# [[ "$A" ]]
-bash: syntax error near unexpected token `"$A"'

This is a bug having to do with resetting the parser state in an
interactive shell after an error token. It was fixed back in October as
the  result of

https://savannah.gnu.org/support/?110745

and the fix is in the devel branch. It's ironic that this is the exact
same issue we discussed yesterday in

https://lists.gnu.org/archive/html/bug-bash/2023-02/msg00150.html

with a slightly different effect.


According to the manual, I think an empty condition like ``[[   ]]'' and
``[[ $EMPTY ]]'' should always triger syntax error,

No. There has to be at least one operand of [[, but since word expansions
are not performed until [[ executes, a variable expansion is a valid
operand. That's the difference between a compound command and a builtin.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/


Reply via email to