Reputation: 9418
I want to use read
to put data into a particular element of an associative array, so I wrote the following:
typeset -Ag aa
aa[key]='initial value'
...
read aa[key]
which produces an error: no matches found: aa[key]
So I write the following instead and it works:
typeset -Ag aa
aa[key]='initial value'
...
local line
read line
aa[key]=line
Is there a way to skip the temporary variable line
?
Upvotes: 2
Views: 162
Reputation: 5319
It seems that zsh trys to do globbing somehow for the aa[key]
token.
So, it would be fine to turn off globbing temporally using noglob
or quoting that token.
echo val0 | noglob read aa[key]; echo $aa[key] ;# => val0
echo val1 | read 'aa[key]'; echo $aa[key] ;# => val1
noglob
Filename generation (globbing) is not performed on any of the words.
Upvotes: 1