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

Re: exported unset variables [was: 'export -p' lacks POSIX output]



[It's once again taking a long time for some messages to reach the
mailing list.  My first message on this thread hasn't even shown up
there yet.]

On Oct 28, 10:48pm, Martijn Dekker wrote:
}
} $ PS1='%% ' Src/zsh -f -o posixbuiltins
} % unset -v var
} % export var
} % echo ${var+s}  # this shows it as set (should be unset)
} s
} % export -p var  # but this shows it as unset
} export var

Ah, I see.  Yes, I mentioned this in the email about the patch.  The
shell variable named "var" becomes set upon being exported, but the
environment copy remains unset until explicitly assigned.  Zsh has
always distinguished the shell variable from the exported variable,
even though the value of the exported variable (if any) is stored in
the data structure for the shell variable.

All my patch did was cause "export -p" to output the state of the
environment variable instead of the state of the shell variable.

See if the patch below will help.

} (Also, is it correct/expected behaviour that zsh doesn't parse comments
} on the interactive command line? Blindly copying/pasting the above won't
} work for that reason.)

Yes, the option INTERACTIVE_COMMENTS has to be set to recognize comments
at the command line.  Should this be on in POSIX mode?


diff --git a/Src/builtin.c b/Src/builtin.c
index 2db739f..183ed45 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2008,11 +2008,12 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
      * handled in createparam().  Here we just avoid using it for the
      * present tests if it's unset.
      *
-     * POSIXBUILTINS horror: we need to retain the 'readonly' flag
-     * of an unset parameter.
+     * POSIXBUILTINS horror: we need to retain the 'readonly' or 'export'
+     * flags of an unset parameter.
      */
     usepm = pm && (!(pm->node.flags & PM_UNSET) ||
-		   (isset(POSIXBUILTINS) && (pm->node.flags & PM_READONLY)));
+		   (isset(POSIXBUILTINS) &&
+		    (pm->node.flags & (PM_READONLY|PM_EXPORTED))));
 
     /*
      * We need to compare types with an existing pm if special,
@@ -2135,7 +2136,8 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	/*
 	 * Stricter rules about retaining readonly attribute in this case.
 	 */
-	if ((on & PM_READONLY) && (!usepm || (pm->node.flags & PM_UNSET)) &&
+	if ((on & (PM_READONLY|PM_EXPORTED)) &&
+	    (!usepm || (pm->node.flags & PM_UNSET)) &&
 	    !ASG_VALUEP(asg))
 	    on |= PM_UNSET;
 	else if (usepm && (pm->node.flags & PM_READONLY) &&



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