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

unset, POSIX and the export attribute (Was: [PATCH] Fix crash on unset-through-nameref)



2024-03-05 10:42:18 -0800, Bart Schaefer:
> On Tue, Mar 5, 2024 at 12:19 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> >
> > 2024-03-04 15:18:06 -0800, Bart Schaefer:
> > > On Mon, Mar 4, 2024 at 11:34 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> > > >
> > > > It still retained its export attribute.
> > >
> > > This gets messy because POSIX says that's exactly what's supposed to
> > > happen when unsetting an export, even though in native zsh it normally
> > > doesn't work that way.
> >
> > No, I think you're confusing with:
> >
> > export foo
> 
> I'm referring to comments in the C code, e.g.:
> 
>      * POSIXBUILTINS horror: we need to retain the 'readonly' or 'export'
>      * flags of an unset parameter.
> [...]
>     if (isset(POSIXBUILTINS)) {
> [...]
>         /* This is handled by createparam():
>         if (usepm && (pm->node.flags & PM_EXPORTED) && !(off & PM_EXPORTED))
>             on |= PM_EXPORTED;
>         */
[...]

But AFAICT, that's about the "export var" when var is not
previously set. You can't unset a readonly variable anyway.

zsh retaining the export attribute of a variable upon unset
would make it non-compliant.

POSIX is not ambiguous on that. See
https//pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/V3_chap02.html#unset

"unset - unset values and attributes of variables and functions"
"Read-only variables cannot be unset."

-- 
Stephane




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