Is there a way to make &>/dev/null the default behavior in a sh/bash script? I' rather not have to appended this to every command within the console, not an *.sh script.

I'm looking to make a global setting...or at least a custom alias of some sort, but one that makes any command and every command, auto-append &>/dev/null to the end.

Any ideas?

  • 10
    Why, on earth, would you want to do this? Output exists for a reason, and though it is helpful to sometimes get rid of that output, making it the default seems very odd to me. – HalosGhost Jul 3 '14 at 20:47
  • 1
    Why?, I need to know. – ctrl-alt-delor Jul 3 '14 at 21:56

Add exec &>/dev/null in the beginning of bash script

  • 1
    ~/.bashrc is suddenly a bash script, too. – tijagi Jul 4 '14 at 0:56

In the shell:

exec >/dev/null
# still shows the prompt
exec 2>/dev/null
# now the prompt is gone, too

# restore stdout
exec >/dev/tty
# restore stderr
exec 2>/dev/tty
  • you can make the prompt go by redefining PS – ctrl-alt-delor Jul 3 '14 at 21:55
  • @richard I did not mean only what the shell prints automatically but also the commands you type (which are not affected by PS1). – Hauke Laging Jul 3 '14 at 22:05
  • @John1024 That's strange: I thought that it should work with /dev/tty. I tested that and it didn't work thus I used the other way. If I test it again now it works... No idea what may have gone wrong before. – Hauke Laging Jul 4 '14 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy