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 12890
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: Check existence of an element of an array (a FAQ?)
- Date: Fri, 30 May 2008 11:57:08 +0200
- Cc: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>, zsh-users@xxxxxxxxxx
- In-reply-to: <tkrat.45b2e7507201e6a1@xxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>, Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <tkrat.6fc8d798a167c9eb@xxxxxxxxxxxxxxxxxxx> <20080530084357.GD2593@xxxxxxxxxxxxxxx> <tkrat.45b2e7507201e6a1@xxxxxxxxxxxxxxxxxxx>
Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>:
> On 30 May, Frank Terbeck wrote:
> > Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>:
[...]
> >> 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
[...]
Both versions will work, if you construct the array correctly.
Both of your attempts to create the array with two items 'me' and
'your' will result in *one* item with the value 'you,me'. Therefore,
both implementations do not find 'me'. Simply because it is not there.
Try: Special_Users=( you me )
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