0

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

3
  • This might help: Reading lines from two files in one while loop Commented Dec 17, 2016 at 14:09
  • but filename2 data change everytime, i need reload filename2 everytime in main loop Commented Dec 17, 2016 at 14:17
  • 1
    It looks to me like your script should work. What's the problem? Commented Dec 17, 2016 at 15:16

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.