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

Re: [BUG] functions can't create global readonly variables



Bart Schaefer schreef op 02-01-16 om 05:27:
> On Jan 2,  4:27am, Martijn Dekker wrote:
> } I don't know if this is intended behaviour for native zsh mode; the
> } 'zshbuiltins' man page does not mention anything about this.
> 
> Of course it does:

I blame insufficient caffeination at the time of writing.

> } But it is certainly a bug for POSIX/'emulate sh' mode.
> 
> I think it's undefined behavior for POSIX/'emulate sh'.  Certainly bash
> agrees with us:
> 
> $ foo() { typeset -r bar; typeset -p bar; }
> $ foo
> declare -r bar
> $ typeset -p bar
> bash: typeset: bar: not found

But 'typeset' is not POSIX. When using the POSIX 'readonly' special
builtin, bash acts like other POSIX shells and unlike zsh:

$ foo() { readonly bar=baz; typeset -p bar; }
$ foo
declare -r bar="baz"
$ typeset -p bar
declare -r bar="baz"

Thanks,

- M.



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