stringbashshellfor-loopcontains

Bash shell string contains print full word


The code:

READLINE=$(sudo /bin/cat < "file.txt");
IFS=$';'
for i in $READLINE;
do
txt=$txt" ""$i";
done
unset IFS

for x in $arr
do
if [[ $txt == *$x* ]] ; then
echo "$x is in the txt file";

Output file.txt

telecomtest;yess;

Output for loop:

telecomtest is in the txt file
tel is in the txt file

I want only print the full word not a part of it.
that means only print telecomtest and not tel.

How can I make this work?


Solution

  • Your $arr appears to contain both telecomtest and tel. There's also a fi missing to make this valid shell grammar.