pkunwor
asked on
Check if string/variable contains another string
How can I check if a variable contains another string in unix
which shell?
ASKER
korn shell
Above code worked, however i am trying to use with if statement and not able to make above work.
e.g. if fullstring contains searchstring then
do st
else
do st else
fi
Above code worked, however i am trying to use with if statement and not able to make above work.
e.g. if fullstring contains searchstring then
do st
else
do st else
fi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i was doing similar if before and was not working, it is working now. Thanks.
b="searchstring"
[ $(echo "$a" | grep -c "$b") -gt 0 ] && echo "String found!" || echo "String not found!"