Skip to content

Instantly share code, notes, and snippets.

@mattmc3 mattmc3/example.zsh
Created Nov 4, 2019

Embed
What would you like to do?
ZSH - array contains value
# http://zsh.sourceforge.net/Doc/Release/Parameters.html#Subscript-Flags
# https://unix.stackexchange.com/questions/411304/how-do-i-check-whether-a-zsh-array-contains-a-given-value/411306
array=(foo bar baz foo)
# 'I' is the subscript flag for index
pattern=f*
if (($array[(I)$pattern])); then
echo array contains at least one value that matches the pattern
fi
# 'I' is the subscript flag for index, 'e' is for exact match
value=foo
if (($array[(Ie)$value])); then
echo value is amongst the values of the array
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.