Subject: Re: [BUG] functions can't create global readonly variables
From: Martijn Dekker <[email-masked]>
To: [email-masked]
Date: Sat, 02 Jan 2016 20:39:25 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

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.