Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] functions can't create global readonly variables
- X-seq: zsh-workers 37486
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [BUG] functions can't create global readonly variables
- Date: Fri, 1 Jan 2016 20:27:10 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=ROR3f59nwSxMtfqJxNLeKjvCvL4CegV6m4i5UJ5xqEg=; b=HxLX1nbO7AsfXg/5/SYXkSSJubqHKjJdXKZbNE+9Y0BGg6y6+Vrk4AfQdOLftQwlXu GXaSTrS5+SAn01eZn2myvOydSH+Y29QaHDSMwlNEH9o3qtB4reUeh2+HRHuA88WVdZIr B2VsEiI3mA0LHRcNYUaW3mjyDXDl+SQzwa/jKBTaK8zgNe0PzmjgFDP+dCH5njN1zbTG 4WdrFRAD2bbYZrz9rqIDWADprOEpXp3YfVwiIhGIqb6IaUSppqnHG1xDk8LhVjznP8Eb Eq+PnVJA2yhxkcAgw9kF/ieSHd4UUzTLdnkQufo72AX28k2LG75sZVCYE10SZsdqcvDO 9BmQ==
- In-reply-to: <56874393.1010001@inlv.org>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <56874393.1010001@inlv.org>
On Jan 2, 4:27am, Martijn Dekker wrote:
}
} It is apparently impossible to create global readonly variables from
} within a function.
typeset -gr var=value
or
readonly -g var=value
} 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:
readonly
Same as typeset -r.
typeset ...
Set or display attributes and values for shell parameters.
A parameter is created for each NAME that does not already refer
to one. When inside a function, a new parameter is created for
every NAME (even those that already exist), and is unset again
when the function completes.
} 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author