How to suppress all output from a command using Bash?


Question

I have a bash script that runs a program with parameters. That program outputs some status (doing this, doing that...). There is no 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".

1
267
1/14/2019 6:27:11 PM

Accepted Answer

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
475
3/6/2009 2:03:57 AM

Something like

script > /dev/null 2>&1

This will prevent standard output and error output, redirecting them both to /dev/null.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon