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

Re: f() { local -ar path=(/bin); };f gives an error



2017-11-26 18:28:17 -0500, Eric Cook:
> On 11/26/2017 06:21 PM, Stephane Chazelas wrote:
> > FYI,
> > 
> > someone reported this on unix.stackexchange.com:
> > https://unix.stackexchange.com/questions/407125/why-cant-i-define-a-readonly-variable-named-path-in-zsh
> > 
> > Which looks like a bug:
> > 
> > $ zsh -c 'f() { local -ar path=(/bin); }; f'
> > f: read-only variable: path
> > $ /zsh --version
> > zsh 5.4.2-dev-0 (x86_64-unknown-linux-gnu)
> > 
> > See also the answer there by someone would did some investigation already.
> > 
> () { local -har path=(/foo); typeset -p path }
> typeset -ar path=( /foo )
> 
> -h     Hide: only useful for special  parameters  (those  marked
>        `<S>' in the table in zshparam(1)), and for local parame‐
>        ters with the same name as a  special  parameter...

Thanks.

But that creates a non-special local "path" variable.

The issue here is that when you're trying to make $path (the
special array variable tied to $PATH) readonly (with a value)
locally in a function, that doesn't work.

it also doesn't work with the scalar variant:

() { local -r PATH=/foo; }

same goes with the $cdpath/$CDPATH variable.

-- 
Stephane



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