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

Re: Weird error message when using bash or ksh form of array initialization



2008/8/24 Rocky Bernstein <rocky.bernstein@xxxxxxxxx>:
> When I run this (erroneous?) program:
>
>  typeset -a fd=()
>  typeset -a sources
>  typeset -i xx
>
> I get a weird error message:
>
>  typeset:3: maximum nested function level reached
>
> Note that neither of these give an error:
>
>  typeset -a fd=()
>  typeset -a sources
>
> or
>
>  typeset -a fd
>  typeset -a sources
>  typeset -i xx
>
> or
>
>  typeset -a fd
>  fd=()
>  typeset -a sources
>  typeset -i xx
>
> Somehow fd= is treated as a function which is indicated out by adding
> a request to print out fd=:
>
>  typeset -a fd=()
>  typeset -a sources
>  typeset -i xx
>  declare -f fd=
>
> Which reports:
>  typeset:3: maximum nested function level reached
>  'fd=' () {
>        typeset -a sources
>  }
>
> Can someone explain what's going on?
>
> Since both bash and ksh allow an array initialization via the form
> used above, it increases the chance of getting this weird error
> message.
>
> Thanks.

I think you need to quote the arguments for typeset,
% typeset -a 'fd=()'
typeset: fd: can't assign initial value for array

Also,
% typeset -a fd=() {}
% which typeset
typeset () {
	
}
% which -- -a
-a () {
	
}

The whole thing probably gets interpreted as a function definition of
the form
name1 name2 name3 () { name1 foo bar }; name1
The function then ends up calling itself recursively which zsh protects
itself against by erroring out after some iterations, no idea how many.

-- 
Mikael Magnusson



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