Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH (not final)] (take three?) unset "array[$anything]"



On Fri, Jun 4, 2021 at 1:21 PM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> while IFS=, read -r a b c; do
>   unset "hash[$b]"
> done < data
>
> And with the stripquotes patch, you'd have the *contents* of $b
> (from external data), not the literal $b string fed to the lexer
> as if it was meant to be zsh code.

It's doing only pure lexical analysis of a single "string" token,
there's no chance of it interpolating anything.

> There's also the fact that we can't do:
>
> hash['foo bar
> baz'$'\n'...]=value

Hmm, you mean because subscripts (even hash subscripts) are parsed as
if in $(( )) and $'...' does not expand there.

> array[1 + 1]=4
>
> That is pretty annoying.

That's just shell whitespace rules, though.  If you have nobadpattern
set, you get

zsh: command not found: array[1

And if the parser doesn't eventually find ]= then what?  Re-parse the
whole thing to word-split it?

I don't think there's any way to retconn word-splitting.  We could
perhaps overload ={...} (or something) so that instead of

: ${array[1 + 1]:=4}

you could write

={array[1 + 1]}=4

but I don't think that's really that much prettier (and unlikely as it
would be to appear in any existing script, that's obviously not
backwards-compatible).




Messages sorted by: Reverse Date, Date, Thread, Author