How do I know if grep command is successful?

How do I know if grep command is successful?
Answer
Another simple way is to use grep -c . That outputs (not return as exit code), the number of lines that match the pattern, so 0 if there’s no match or 1 or more if there’s a match. So, if you wanted to check that the pattern is matched 3 or more times, you would do: if [ “$(grep -c “^$1” schemas.
 

Tìm kiếm

Back
Top