John Y
John Y

Reputation: 1271

How to add to an associative array in zsh?

I'm trying to change an element of a zsh associative array, but I can't find any clues on the correct syntax.

The PHP equivalent would be

$assoc['key'] = 'newvalue';

but how can I do this in zsh?

The documentation seems to be very confusing on this, as it assumes that once you've set up an associative array, you never want to change it.

EDIT: this is what I'm trying to do

% noglob ZSH_HIGHLIGHT_STYLES[globbing]='fg=yellow' zsh: command not found: ZSH_HIGHLIGHT_STYLES[globbing]=fg=yellow

$ZSH_HIGHLIGHT_STYLES is defined by the zsh-syntax-highlighting plugin.

Upvotes: 9

Views: 9577

Answers (1)

chepner
chepner

Reputation: 531325

It's actually pretty simple, assuming you have an associative array.

typeset -A assoc
assoc[key]=newvalue

Upvotes: 17

Related Questions