Loop until grep does not find the text in a file
From grep
man page:
EXIT STATUS
Normally the exit status is 0 if a line is selected, 1 if no lines were
selected, and 2 if an error occurred. However, if the -q or --quiet or
--silent is used and a line is selected, the exit status is 0 even if
an error occurred.
So if a line is present, the exit status is 0. Since on bash 0 is true (because the standard "successful" exit status of programs is 0) you should actually have something like:
#!/bin/bash
while grep "sunday" file.txt > /dev/null;
do
sleep 1
echo "working..."
done
Why exactly are you piping sleep 1
to echo
? Though it works, it doesn't make much sense. If you wanted them inline you could just write sleep 1; echo "working..."
and if you wanted the echo
to run before the delay, you could have it before the sleep
call like echo "working..."; sleep 1
.