Tuesday, 20 August 2013

Comparison of 2 string variables in shell script

Comparison of 2 string variables in shell script

Consider there is a variable line and variable word:
line = 1234 abc xyz 5678
word = 1234
I want to print the line if it contains the word. How do I do this using
shell script? I tried all the suggested solutions given in previous
questions. For example, the following code always passed even if the word
was not in the line.
if [ "$line"==*"$word"*]; then
echo $line
fi
Please help. Thanks.

No comments:

Post a Comment