0

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?

2
  • 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, 2014 at 20:47
  • 1
    Why?, I need to know. Jul 3, 2014 at 21:56

2 Answers 2

6

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

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

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
3
  • you can make the prompt go by redefining PS Jul 3, 2014 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). Jul 3, 2014 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. Jul 4, 2014 at 2:31

You must log in to answer this question.