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

[PATCH] posix_builtins: allow exporting a readonly



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. It simply checks if we are running the 'export' command and then reverts to normal behaviour instead of the special-casing for POSIXBUILTINS which is incorrect for this case.

Note that the patched code block is only executed with POSIXBUILTINS active so won't otherwise affect anything in any case.

Also, attempts to assign using 'export' still correctly error out with the patch, as they do on other shells:

$ zsh --emulate sh -c 'readonly foo=123; export foo=123'
zsh:1: read-only variable: foo

Thanks,

- M.

--
modernish -- harness the shell
https://github.com/modernish/modernish



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