Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [[ is being treated as a pattern in the command/reserved word position.
29.03.2015, 02:07, "Eric Cook" <llua@xxxxxxx>:
> On 03/28/2015 06:33 PM, ZyX wrote:
>> 29.03.2015, 01:25, "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>:
>>> On Mar 28, 5:55pm, Eric Cook wrote:
>>> }
>>> } % print $ZSH_PATCHLEVEL; emulate sh -c '[[ a == a ]]'
>>> } zsh-5.0.7-362-gab40656
>>> } zsh: command not found: [[
>>> }
>>> } Did that behavior change?
>>>
>>> Aha. That makes more sense.
>>>
>>> The '[[' reserved word is handled a special kind of built-in alias [*]
>>> and the change to POSIX_ALIASES handling caused that to be disabled.
>>>
>>> This will take a bit of thought.
>>>
>>> [*] Not literally, but the alias expansion code is where '[[' is noted
>>> and the lexer changed into "parsing a conditional" state.
>> I would say that this is actually an expected behaviour: `posh -c '[[ a == a ]]'` will show `posh: [[: not found` because `[[` is not in POSIX. Similar error will be shown by dash.
>
> Nor is it disallowed by POSIXand it used to work, the bug report is
> still valid.
`[[` is a *syntax extension*. This *is* going against POSIX. If `[[` in POSIX emulation mode was implemented as a shell built-in in a manner that allows implementing it as a script your concern would be valid. But implementing `[[` as a shell built-in is breaking certain expectations about how `[[` is supposed to work.
Specifically, with
setopt SH_WORD_SPLIT
w="a = b"
test $w # False: a ≠ b, expected
[[ a = b ]] # False: a ≠ b, expected
[[ $w ]] # True: w is not empty, should be false if shell is POSIX
. It is easier to disable `[[` then keep two implementations of it.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author