Sign up ×
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.

I'm building a shell script to automatically configure a specific computer with the best settings. I would like to hide all output from this script except for echo output. Is it possible?

share|improve this question
    
You can end each line in &> /dev/null except the echos. –  LatinSuD Jun 24 '14 at 13:32

2 Answers 2

up vote 5 down vote accepted

Start your script with:

exec 3>&1 1>/dev/null 2>&1

That will save your original file descriptor for stdout to &3, and then redirect stdout and stderr to /dev/null. Whenever you want to print something, redirect its output to &3, like:

echo "This message won't be output"
echo "But this one will" >&3

And if you want to hide that detail, you can just define a function that echoes to fd 3:

say() {
    echo >&3 "$@"
}

say "This goes to the log"
share|improve this answer
    
It worked, thank you –  Dremor Jun 24 '14 at 14:59

You can redirect stdout to /dev/null by adding

1>/dev/null

at the end of each line of your script that will produce output.

You can redirect errors the same way by adding

2>/dev/null

Most commands also have an option to turn off normal output to the console like -q or something like that. Check the manpages of the commands you use.

share|improve this answer

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.