Bash Scripting – Suppressing Script Command Outputs
Other Learning Articles that you may like to read
Free Courses We Offer
Paid Training Courses we Offer
Sometimes, you may not want to display any output from your script. This often occurs if you’re running a script as a background process. If any error messages occur from the script while it’s running in the background, the shell e-mails them to the owner of the process. This can get tedious, especially if you run scripts that generate minor nuisance errors.
To solve that problem, you can redirect STDERR to a special file called the null file. The null file is pretty much what it says it is — a file that contains nothing. Any data that the shell outputs to the null file is not saved, thus the data are lost.
$ ls -al > /dev/null $ cat /dev/null $
You can also use the /dev/null file for input redirection as an input file. Because the /dev/null file contains nothing, it is often used by programmers to quickly remove data from an existing file without having to remove the file and re-create it:
$ cat testfile This is the first line. This is the second line. This is the third line. $ cat /dev/null > testfile $ cat testfile $