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

Re: special characters in file names issue



In reversed order ...

On Fri, Nov 10, 2023 at 12:38 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Fri, Nov 10, 2023 at 6:03 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > -v has to evaluate the subscript to find the array element [...]
>
> Why does it have to evaluate the subscript? `unset` does not do it,
> why would [[ -v .. ]] be different?

The shortest possible answer is that [[ -v ... ]] will autoload the
parameter before reporting whether it is set, whereas unset just acts
on the current state.

% typeset -p aliases
% unset 'aliases[run-help]'
zsh: aliases: assignment to invalid subscript range
% [[ -v aliases[run-help] ]] && echo yes
yes
%

However, I doubt Oliver was specifically thinking about that seven
years ago when he implemented [[ -v ... ]].

> On Fri, Nov 10, 2023 at 5:34 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
> >
> > Subscripted arguments to [[ -v ... ]] appear to undergo a second
> > round of expansions [...]
>
> There is also a scarier version of this, which causes execution of an
> external command when I don't expect it.

This is why the new named-references code evaluates subscripts with
NO_EXEC temporarily in effect.

> Is this intended?

That answer is probably lost to history.  If we presently believe that
"no" is the best answer, we can use the NO_EXEC trick for [[ -v ... ]]
as well, although that would mean that a bit of factored-out code
that's currently called only from [[ ]] could never be called from
anywhere else.




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