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

Re: [PATCH] posix_builtins: allow exporting a readonly



Op 21-06-19 om 09:59 schreef Peter Stephenson:
On Thu, 2019-06-20 at 19:47 +0100, Martijn Dekker wrote:
Op 18-04-18 om 20:58 schreef Martijn Dekker:
POSIX_BUILTINS incorrectly prohibits exporting a readonly variable. All
other POSIX shells allow this and there is nothing in the POSIX text[*]
that says it's not allowed. The attached patch fixes this.
This seems to have been forgotten about, so I'm trying again.
To recap: $ zsh -c 'readonly foo=123; export foo' # OK
$ zsh --emulate sh -c 'readonly foo=123; export foo'	# BUG
zsh:1: read-only variable: foo
I had another look at it and I think this patch (attached) should be
even more straightforward.

This sounds fine but I don't think there is an attachment.

Woops. :-/

Here it is...

- M.
diff --git a/Src/builtin.c b/Src/builtin.c
index 2453f82c0..e863cc4bb 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2171,7 +2171,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	    !ASG_VALUEP(asg))
 	    on |= PM_UNSET;
 	else if (usepm && (pm->node.flags & PM_READONLY) &&
-		 !(on & PM_READONLY)) {
+		 !(on & PM_READONLY) && func != BIN_EXPORT) {
 	    zerr("read-only variable: %s", pm->node.nam);
 	    return NULL;
 	}


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