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

[doogie@xxxxxxxxxx: Bug#163391: unset array[key] where key is non-existent doesn't fail]

I'm not sure to what "contract" he's referring, but SUSv3 says

  Unsetting a variable or function that was not previously set shall not
  be considered an error and does not cause the shell to abort.

and that unset should return a >0 exit status if any of the "name"
operands cannot be unset.

Of course, it knows nothing about associative arrays.

----- Forwarded message from Adam Heath <doogie@xxxxxxxxxx> -----

bash-2.05b$ zsh -c 'unset non_existant_var && echo error || echo
correct; unset "array[1]" && echo error || echo correct; declare -A
aarray; unset "aarray[foo]" && echo error || echo correct'

The contract for unset says that if the variable being unset doesn't exist, an
error is returned.  As shown above, variables and normal arrays behave as
expected, but associative arrays do not.

----- End forwarded message -----

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