Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
9  
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
    
Why?, I need to know. –  richard Jul 3 '14 at 21:56

2 Answers 2

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

share|improve this answer
    
~/.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
share|improve this answer
    
you can make the prompt go by redefining PS –  richard 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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.