if grep ttt $i > /dev/null 2> /dev/null
It is not clear what questions, but if you want to say "what does this line do?":
if grep ttt $i > /dev/null 2> /dev/null
what you are doing is executing the grep
command to find the text ttt
in the file whose name is contained in the variable $i
, but discard what grep
would show on the screen (since the operator >
is redirecting the standard output to the pseudo-file /dev/null
, which is simply a black hole that makes everything you type in it disappear, and the operator 2>
does the same with the error output).
Even if we have discarded the output of grep
, however, we are using your exit status , because that is what if
checks. If the exit status of grep
is 0 (which would indicate that it found matches in the file), then the condition of if
will be true and the body of that if
(which no samples, and would go between a then
and a fi
). If the exit status is nonzero, that indicates that grep
found no matches, and the body of if
is not executed.