An aspect of programming in a shell environment is an entity called /dev/null.
/dev/null is a special virtual device of no data or content. If data is sent to it, it's discarded. If data is read from it, it is null/empty.
So, what good is a device that throws everything away we send to it, or provides us with nothing to use?
Good question. /dev/null (sometimes known as the bit bucket), is used in cases where you don't need to actually see the response, but do need to act on it.
Every time we execute a command, it returns an exit status, which the system understands and may respond to.
If the result of a command is successful, the exit status is 0, otherwise it is something greater than 0.
We can check the value of the exit status by using the variable $?. It holds the exit value of the last program the shell executed.
ls /fubar ls: /fubar: No such file or directory echo $? 1 ls -al /dev/null crw-rw-rw- 1 root wheel 0x3000002 Dec 15 12:35 /dev/null echo $? 0
So again with the questions! What's the point of '/dev/null'?
In the first example above, we tried to get a list of files from a directory that did not exist. The system told us that, and quit.
But, instead of quitting, we could check the exit status, and do something else!
This feature is useful once we get into scripting, and not so much in command-line work.