Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Check existence of an element of an array (a FAQ?)
- X-seq: zsh-users 12889
- From: Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>
- To: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>, Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- Subject: Re: Check existence of an element of an array (a FAQ?)
- Date: Fri, 30 May 2008 11:51:17 +0200 (CEST)
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <20080530084357.GD2593@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <tkrat.6fc8d798a167c9eb@xxxxxxxxxxxxxxxxxxx> <20080530084357.GD2593@xxxxxxxxxxxxxxx>
- Reply-to: jarausch@xxxxxxxxxxxxxxxxxxx
On 30 May, Frank Terbeck wrote:
> 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]
>
Sorry, but I seem to have missed something.
I tried both methods without success.
Here is my script and the output.
(It's ZSH CVS from today)
#!/bin/zsh
echo $ZSH_VERSION
Special_Users=('you','me')
U='me'
# same with
# Special_Users=(you,me)
# U=me
if [[ -n ${(M)Special_Users:#${U}} ]] ; then
echo $U is in there - Version 1
else
echo not found - Version 1
fi
if (($Special_Users[(Ie)$U])); then
echo $U is in there - Version 2
else
echo not found - Version 2
fi
# output:
# 4.3.6-dev-0
# not found - Version 1
# not found - Version 2
Many thanks for enlightening me,
Helmut.
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Messages sorted by:
Reverse Date,
Date,
Thread,
Author