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

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



2021-06-13 14:44:03 -0700, Bart Schaefer:
> On Sun, Jun 13, 2021 at 12:50 PM Peter Stephenson
> <p.w.stephenson@xxxxxxxxxxxx> wrote:
> >
> > Yes, in fact those are the same thoughts that flitted through my mind.
> 
> One other idea ... NO_UNSET could warn if you unset something that's
> not set, as well as when you $deref something that's not set.  That
> would at least blat at you if your hash key was misinterpreted.

Note that nounset is a POSIX option. And for the unset special
utility:

"Unsetting a variable or function that was not previously set
shall not be considered an error and does not cause the shell to
abort."

POSIX has no jurisdiction over arrays/hashes, but that does mean
we can't have unset fail on unset variables when in sh emulation
at least.

A shell that would fail upon:

  unset var

When var was not previously set would not be compliant.

A script that would do

  unset "var[foo]"

Would not be a POSIX script as var[foo] is not a valid variable
name, so implementations are free to do whatever they want for
them. But if zsh returned failure for when var[foo] is not set
and not in unset var, that would make it quite inconsistent.

Changing the behaviour would likely break some scripts that use
errexit as well.

-- 
Stephane




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