3

I'm not meaning multiple conditions, well it's also but mixed from that:

while [[ read line ] && [ "$GoodURL" == "false" ]]

What is the correct form for that? It's a while loop that runs on a text file line by line, and I want to stop it with that $GoodURL type of boolean, please help. Thanks.

1 Answer 1

6
while read line && [[ "$GoodURL" == "false" ]]
do 
    echo $line; 
done

In case you want to read from a file/pipe, be sure to use indirection or you will get funny results (due the while loop executing in a subshell and not actually using the same environmen as the surrounding shell)

while read line && [[ "$GoodURL" == "false" ]]
do 
    echo $line; 
done < input.txt
Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't work if I check if a process is still running. For example, while read LINE && [[ pgrep "gnote" > /dev/null ]] fails. pgrep gedit checks if a application is still running.` Is there any other way I can make it work
Ah . Sorry. while read LINE && pgrep "gnote" > /dev/null. This fails as well.
@KhurshidAlam Works like a charm for me. Of course, pgrep runs /after/ read and and exiting gnote does not interrupt that. You need to ask your own question.

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.