tail | grep -q always returning true

Viewed 2967

When I execute this code, the loop always ends at first time (even when the last two lines of auth.log doen't contain "exit"), which means that $c always gets some string:

while true;
do
    c=$(tail -2 /var/log/auth.log | grep -q "exit")
    if $c ;
    then
            echo "true"
            unset c
            break
    fi

done

Do you know why c=$(tail -2 /var/log/auth.log | grep -q "exit") is always getting some kind of string? I think it is becaues of tail.

I can use the -o option and then compare strings, but I prefer to use a boolean inside the if condition.

1 Answers
Related