bug-bash
[Top][All Lists]
Advanced

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

Re: Behaviour of an empty conditional expression is undefined?


From: Chet Ramey
Subject: Re: Behaviour of an empty conditional expression is undefined?
Date: Thu, 23 Feb 2023 10:23:11 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

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    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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