@jimmij gave a great answer, and that works in the general case for printing the matches to the pattern for each key in an associative array.
In the case of zsh
environment variables, however, there's a built-in solution I found using the typeset
command when I was reading man zshbuiltins
.
You can just use typeset
's -m
option, and supply in quotes the pattern of parameter names you are trying to match.
Printing Environment Variables Matching a Pattern
Just the variable name:
typeset +m 'foo*'
foo
foo_fighters
food
Variable name and assigned value:
typeset -m 'foo*'
foo=bar
foo_fighters=awesome
food=(my life)
Typeset flags, variable name, and assigned value
typeset -p -m 'foo*'
typeset foo=bar
typeset foo_fighters=awesome
typeset -a food=( my life )