Re: string pattern matching

From: Reinhard Skarbal (aon.912045243_at_aon.at)
Date: 07/09/03


Date: Wed, 9 Jul 2003 18:48:29 +0200

Try grep :

if echo $i | grep '^abc$' >/dev/null
  then
     print "found"
  else
     print "not found"
fi

( example for ksh )

regards
    Reinhard
"melissa_benkyo" <wyl_lyf@yahoo.com> schrieb im Newsbeitrag
news:304f3217.0307090732.74cae060@posting.google.com...
> hello! I'd like to ask how to do this:
> I have a variable lets say
> test1[0]="abc"
> test1[1]="def"
> test1[2]="def | abc"
>
> How do I go about to test if the variable contains the exact pattern
string "abc"
>
> cause I tried to do
> for i in "${test1[@]}" ; do
> if [[ $i = ^abc$ ]] ; then
> echo "found it"
> fi
> done
>
> but this doesnt work. does anybody know how come? thanks!



Relevant Pages