0

A variable holds the string as, nameList="abc bcd bcde cdefg" and another variable has string as, checkname="bcd".

Now i have to check if $checkname is present in $nameList or not. It should search for exact value only.

For eg. if we check for "bcd" it should throw yes, if we check for "bc" it should throw no. I need this condition check in "if" condition

Thanks.

impika
  • 107
  • 3
  • 11

1 Answers1

0

a simple for loop could do this :

for word in $nameList 
do 
   if [ "$checkname" == "$word" ] 
   then 
        echo found 
        break  
   fi
done
nullPointer
  • 4,419
  • 1
  • 15
  • 27