Article Image

Bet you don't know what >&- does? According to Jeff @ stackoverflow:

/your/first/command >&- 2>&-

Be careful to note the order: >&- closes stdout, which is what you want to do; &>- redirects stdout and stderr to a file named - (hyphen), which is not what what you want to do. It'll look the same at first, but the latter creates a stray file in your working directory. It's easy to remember: >&2 redirects stdout to descriptor 2 (stderr), >&3 redirects stdout to descriptor 3, and >&- redirects stdout to a dead end (i.e. it closes stdout).

This is one way for quieting commands. The other, more common method (and better solution), is /dev/null:

echo "Hello?" > /dev/null

For output redirection to a file, you can direct EVERY output file descriptor to the same place very concisely, but only in bash:

/your/first/command &> /dev/null

and the one everyone loves (silence all output):

/im/just/a/command > /dev/null 2>&1

Enjoy your scripting!

Blog Logo

Mario Loria




Because gets old after a while.

Back to Overview