I have the grep
command. I'm searching for a keyword from a file, but I don't want to display the match. I just want to know the exit status of the grep
.
|
||||
|
If you're using GNU grep it has the switch
Other versions of ExampleString exists:
String doesn't exist:
|
|||||||||||||
|
Just redirect output of
|
|||||||||
|
You simply need to combine You can use this to build up a command like this, for example:
You can optionally suppress output from
This will print |
||||
|
If you don't want to see any output, you need to redirect both stderr and stdout to /dev/null. The other answers are good but won't suppress errors, such as trying to read from a non-existent or unreadable (e.g. wrong permissions) file. Append
If you've already verified that the target file exists and is a file and you have permissions to read it, this isn't that important, but if you're being a little more careless and grepping recursively or using wildcards, you're more likely to see output on stderr. |
|||||||||
|