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:27, "Eric Cook" <llua@xxxxxxx>:
> On 03/28/2015 07:19 PM, ZyX wrote:
>> 29.03.2015, 02:07, "Eric Cook" <llua@xxxxxxx>
>> `[[` 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.
>
> See 2.4 of:
> http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
>> The following words may be recognized as reserved words on some
>
> implementations (when none of the characters are quoted), causing
> unspecified results:
>> [[ ]]functionselect
There is a bit of problem: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_05 (Field Splitting) section does not talk about any exceptions for the field splitting. There is only one official exception to this rule: function definition. I cannot say whether “uspecified result” makes current behaviour of `[[` (non-)conformant.
There is also another consideration: POSIX does not define `[[`. So when you run an emulation mode *what exactly* should `[[` do? When emulating `bash` (not present for some reason) or `ksh` this is defined by those shells, but `sh` is clearly not a bash emulation (reasoning: BASH_REMATCH is not set) and not ksh emulation (reasoning: `emulate ksh` is a distinct emulation mode and `sh` emulation mode is not referenced as an alias of `ksh` emulation mode). I have failed to find what zsh developers meant by `sh` emulation exactly though: it is not explicitly said that it emulates POSIX shell. But since it not bash or ksh emulation mode `[[ $w ]]` in the above case should be `false` (busybox emulation) or a command-not-found error (posh or dash emulation).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author