Originally Posted by nbonda
I am learning shell scripting. I came across "> /dev/null" many times, As a beginner I know that means "redirecting output to trash.
As a beginner, do you also know the difference between "output" and "return code" or "exit status"? I didn't when I was new, so just in case:
Typically, output is written to the controlling terminal. (The user's own shell in this case.) You're probably used to using grep for its output: take whatever came in, apply the filter, and show us what the filter doesn't remove.
The exit status, or return code, is a number that's sent to the controlling process when a program ends. Typically, a value of "0" means that the program ended successfully, and some other number means there was some kind of error, or otherwise "not typical" exit status. Usually when we use the shell, we don't see the exit status, especially if everything is going according to plan.
Typically, the exit status isn't what we use grep for. It's a filter, and we're interested in its output. But when grep doesn't let anything through at all, that's considered an error, so the exit status is set to "1", and that can be useful sometimes, as in your case.