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: Kerin Millar
Subject: Re: Behaviour of an empty conditional expression is undefined?
Date: Thu, 23 Feb 2023 10:12:12 +0000

On Thu, 23 Feb 2023 16:26:43 +0800 (CST)
"Qingsheng Huang" <huangqqss@126.com> 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"'
> infinite:~# [[ "$A" ]]
> infinite:~# [[ "$A" ]]
> infinite:~# [[ ]]
> infinite:~# [[ "$A" ]]
> -bash: syntax error near unexpected token `"$A"'
> infinite:~# echo $?
> 2
> infinite:~# [[ "$A" ]]
> infinite:~# echo $?
> 1
> infinite:~#
> infinite:~# bash --version
> bash --version
> GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
> ------------------------------------------------------------------------
> 
> The variable $A has never been defined.
> Double brackets surrounding 1) a few spaces or 2) an empty variable even
> quoted behave illogically.  I've also try different lengths of spaces, and
> also an empty variable without quotes, the same illogical.
> 
> I am curious if I am the first guy encounter such a situation.

Well observed. I can confirm this strange behaviour. I just want to add that 
5.1.16 behaves sensibly, with [[ ]] always raising an error in an interactive 
shell.

-- 
Kerin Millar



reply via email to

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