akram
akram

Reputation: 113

Read 2 file in bash with loop

i want to make echo username inside userlist.txt, and check the main loop if username is inside chk.txt, and pause 60 second before continue the main loop

filename1="/home/user/userlist.txt"
while read -r  file1
do
    filename2 = "/home/user/chk.txt"
    while read -r file2
    do
      text2 = $file2
      if $file2 == "username"
         pause 60
    done < "filename2"


    text="$file1"
    txt=($file1)
    name=${txt[0]}
    echo $name
    sleep 10

done < "$filename1"

sorry for really bad explaination

Upvotes: 0

Views: 67

Answers (1)

Barmar
Barmar

Reputation: 780843

You have some basic syntax errors.

When assigning variables, you can't have spaces around =. So it should be:

filename2=/home/user/chk.txt
text2=$file2

In the if, you're missing the [ command to perform a test, and the then and fi keywords.

if [ "$file2" = "username" ]
then
    sleep 60
fi

There's no pause command, it's sleep (you get it right later in the script).

But if you just want to check if a word is inside a file, you don't need a loop, you can use the grep command.

if grep -q username $file2
then
    sleep 60
fi

Upvotes: 1

Related Questions