1

I'm new to zsh and have discovered some strange behavior, but this tops it all.

I just came across this extremely strange behavior when declaring a local array in a zsh function that I was writing for my .zshrc file. When I declared a local array it caused my prompt to go crazy. I eventually traced it back to two very strange functions that randomly got created. I reduced it to a simple case:

% function () { local foobar=(); echo frog; }
% echo ${functions[foobar=]}
        echo frog
% echo ${functions[local]}
        echo frog

The first strange thing is that frog never gets printed from the anonymous function. But the really strange thing is that instead two functions named foobar= and local get created.

This causes all kinds of problems for my zsh prompt. Whenever the local keyword is used it printed frog.

I am really wondering what on earth caused zsh to create those functions.

I am using zsh 5.0.2

1

I found that it must have been a bug in my version of zsh. I upgraded to zsh 5.6.2 and found that the behavior was fixed in that version. I also have a theory as to what zsh was trying to do in the problem situation. When I run:

% foo bar() echo hi

It creates two functions, foo and bar, both of which simply echo hi.

I think that zsh had been interpreting local foobar=() as defining two functions: local and foobar=. This is really bizarre, as I didn't think that local or foobar= would be valid function names. I'd be curious to see where the bug was in zsh source.

I also found that the proper way to declare a local array is local -a foobar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.