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

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



On Fri, May 30, 2008 at 10:40:30AM +0200, Helmut Jarausch wrote:
[...]
> 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
[...]

if (($Special_Users[(Ie)$U])); then
  # do something
fi

Note that the (e) flag is a recent addition to zsh. You can
ommit it, but then $U is taken as a pattern.

-- 
Stéphane



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