Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Check existence of an element of an array (a FAQ?)



Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>:
> please help me with the following:
> 
> Is there an elegant way (i.e. without a loop) to
> get the following action
> 
> Special_Users=('you','me',......)
> 
> U='nobody'
> 
> if  $U in $Special_Users
>   # do something
> fi

[snip]
if [[ -n ${(M)Special_Users:#${U}} ]] ; then
    echo $U is in there
fi
[snap]

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



Messages sorted by: Reverse Date, Date, Thread, Author