views:

4705

answers:

3

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".

+15  A: 

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
andynormancx
ohh Thank you, that's exactly what I was looking for :)
6bytes
Note that '
Jonathan Leffler
Ah, I've only ever really used bash.
andynormancx
@andy, incorporated comments into your answer and added Windows stderr redirection as well. Then I +1'ed you for a good answer :-)
paxdiablo
+5  A: 

Something like

script > /dev/null 2>&1

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

Diego Sevilla
Also achieved with just )
andynormancx
True... out of habit :)
Diego Sevilla
A: 

Like andynormancx post use this: (if you're working in an Unix environment)

scriptname > /dev/null

or you can use this: (if you're workin in a Windows environment)

scriptname > null

The 'null' can be anything, this will create a file with that name and will write all the output there. Then you can delete that file.

unkiwii
You can actually do better than that in the Windows shell. If instead you use "scriptname > nul" then you won't even have a file to delete, as "nul" is the Windows equivalent of /dev/null.
andynormancx
@andynormancx: That's what I hate about the Windows file system layout. It "reserves" filenames like NUL, COM1, LPT1, CON, etc, no matter what directory you're in (even if you're in a file-system that can have those filenames, like in network shares).
dreamlax
I don't think I've actually used NUL since DOS 5.x, had a sudden flash of remembrance when I saw this answer ;)
andynormancx