Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to search for a substring in a parameter?
- X-seq: zsh-users 5690
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: how to search for a substring in a parameter?
- Date: Mon, 13 Jan 2003 18:26:02 +0000
- In-reply-to: <15907.432.363150.443412@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <15907.432.363150.443412@xxxxxxxxxxxxxx>
On Jan 13, 4:13pm, Carlos Carvalho wrote:
}
} I'm trying to see if the value of a parameter contains a given string
The right-hand-side of == in a [[ ]] construct is a glob pattern, so if
all you want is true/false, this works:
if [[ $foo == *pattern* ]]; then
# contains pattern
else
# doesn't contain pattern
fi
If you want to extract the matching string, see the M and S flags:
matching=${(SM)foo##pattern}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author