In my shell script I got these lines:
rm tempfl.txt rm tempfl2.txt If these do not exist I get the error messages:
rm: tempfl2.txt: No such file or directory rm: tempfl.txt: No such file or directory Is there a way to only suppress these messages even though they do not always appear, as the files might exist?
You can ignore standard error on screen when you write stderr to /dev/null .
To silence the output of a command, we redirect either stdout or stderr — or both — to /dev/null. To select which stream to redirect, we need to provide the FD number to the redirection operator.
You have two options:
Suppress rm warnings
$ rm tempfl.txt 2> /dev/null Redirect script output to /dev/null
$ ./myscript.sh 2> /dev/null The latter has a drawback of missing all other warning messages produced by your script.
As the other answers state, you can use command 2> /dev/null to throw away the error output from command
But what is going on here?
> is the operator used to redirect output. 2 is a reference to the standard error output stream, i.e. 2> = redirect error output.
/dev/null is the 'null device' which just swallows any input provided to it. You can combine the two to effectively throw away output from a command.
Full reference:
> /dev/null throw away stdout 1> /dev/null throw away stdout 2> /dev/null throw away stderr &> /dev/null throw away both stdout and stderr If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With