7

If supported, which version of zsh should I use to take advantage of this feature? How to declare and use it in code?

1 Answer 1

16

Zsh supports hash tables, a quick google search returns many results.

You must first typeset the variable:

% typeset -A hash

then you can store items in the table:

% hash[brown]="mm..  hash browns"
% hash[table]="clever data structure"

then you recover them as usual with arrays:

% print ${hash[brown]}
3
  • 2
    Just a remark: This kind of variables are called associative arrays in zsh.
    – mpy
    Aug 24, 2013 at 12:13
  • 1
    So they are in PHP, also; it's the rest of the world that calls them hash tables.
    – Fanfurlio
    Aug 26, 2013 at 8:56
  • 1
    in PHP they are hash tables but, associative arrays don't have to be hash tables: stackoverflow.com/questions/3134296/… Apr 27, 2021 at 16:59

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.