Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress all output from a command using Bash?

I have a Bash script that runs a program with parameters. That program outputs some status (doing this, doing that...). There isn't any option for this program to be quiet. How can I prevent the script from displaying anything?

I am looking for something like Windows' "echo off".

like image 931
6bytes Avatar asked Mar 05 '09 23:03

6bytes


People also ask

How do you abort a command in bash?

There are many methods to quit the bash script, i.e., quit while writing a bash script, while execution, or at run time. One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.

How do you negate an expression in bash?

NegationWhen we use the not operator outside the [[, then it will execute the expression(s) inside [[ and negate the result. If the value of num equals 0, the expression returns true. But it's negated since we have used the not operator outside the double square brackets.

How do I suppress grep output?

The quiet option ( -q ), causes grep to run silently and not generate any output. Instead, it runs the command and returns an exit status based on success or failure. The return status is 0 for success and nonzero for failure.


1 Answers

The following sends standard output to the null device (bit bucket).

scriptname >/dev/null 

And if you also want error messages to be sent there, use one of (the first may not work in all shells):

scriptname &>/dev/null scriptname >/dev/null 2>&1 scriptname >/dev/null 2>/dev/null 

And, if you want to record the messages, but not see them, replace /dev/null with an actual file, such as:

scriptname &>scriptname.out 

For completeness, under Windows cmd.exe (where "nul" is the equivalent of "/dev/null"), it is:

scriptname >nul 2>nul 
like image 182
andynormancx Avatar answered Oct 02 '22 19:10

andynormancx