In the shell script, called the variable options. The script fails. If renamed, there is no error. Is this a reserved name? What does the error "attempt to assign a part of an associative array" mean?

This does not work:

function mcve() { options=''; echo 'ok'; } $ mcve mcve:1: options: attempt to set slice of associative array 

And so - it works.

 function mcve() { opts=''; echo 'ok'; } $ mcve ok 

zsh 5.0.5 (x86_64-apple-darwin14.0)

UPD. According to man zshmisc , this word is not reserved.

If you are using the command word, you can disable -r .

do done esac then elif else fi for case if while function repeat time until select coproc nocorrect foreach end ! [[ { }

UPD2.

Before the first function call with the string options=''; (which gives an error):

 $ declare options options 

After calling the function:

 $declare options options=(autolist on printexitvalue off...<20 строк опций>) 

And this syntax passes without errors.

 function mcve() { declare options; options=''; echo ok; } $ zsh $ mcve ok 

1 answer 1

probably options described as an associative array.

You can see its current content, for example, like this:

 $ declare options 

judging by its content, it is described in man zshoptions .

  • those. is it a variable declared by zsh? How can I get a complete list of such variables? - Nick Volynkin
  • variable declared by zsh? - it would be more correct to say, probably, “received a value in one of the starting scripts”. A list of declared arrays can be obtained with the declare command (without arguments). the list of declarations of functions — the set command (the environment variable is also listed there, which has no direct relation to the shell). in addition, there is an env program that returns (without arguments) a list of environment variables - but this is no longer directly related to the shell. - aleksandr barakin
  • More, perhaps, the alias command is worth mentioning - it gives a list of the alias shells defined in this session. - aleksandr barakin
  • Updated the answer. It seems as if the value it receives at the time of the error. Or I do not understand something very important in declaring variables in zsh. - Nick Volynkin
  • Well, judging by the fact that (I) does not allow zsh to change the contents of this array, this array is apparently attributed by zsh developers to the category “internal”, and judging by its contents, it is a “reflection” of what is described in man zshoptions . - aleksandr barakin