Issue
I am working with shell scripts for some automation tasks. I have functions defined in my script which are executed however the tasks performed by some of the functions logs a lot of data on the terminal screen which is irrelevant.
Is there a way in which I can suppress the console logging before calling a particular function and enable it back when the function execution is finished?
Solution
You can supress the output of a program redirecting it to the special file /dev/null
.
Note that there are two kind of output, normal output (stdout
) and error output (stderr
)
To redirect all output use
command_or_function [args] &>/dev/null
If you want to supress the output for multiple commands, use { }
{
...
commands
...
} &>/dev/null
The redirection can be placed at any position, even before command.
&>/dev/null echo hello
To redirect only stdout
use >
To redirect only stderr
use 2>
Answered By - nadapez Answer Checked By - Marie Seifert (WPSolving Admin)