Shell Script: making this exit [closed]

0
 if grep ttt $i > /dev/null 2> /dev/null
    
asked by lethal_shooter 03.05.2018 в 15:29
source

1 answer

1

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.

    
answered by 03.05.2018 в 19:56