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.

I'm trying to have a script exit with an error in the event it can't reach an X server:

xset -q &> /dev/null || { echo "The Display Server is BROKEN.  Aborting."; exit 1; }

However, I'm getting the output of xset -q spat out to the console. I'm not quite sure why. My understanding of &> was that it redirected all output.

Can somebody assist?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

If you want to redirect the STDOUT and STDERR to /dev/null for xset -q, you should do:

xset -q > /dev/null 2>&1 || { echo "The Display Server is BROKEN.  Aborting."; exit 1; }

The redirection of using &> only works within bash or zsh. Therefore you should use 2>&1 to let redirection work in all Bourne-like shells.

share|improve this answer
    
Thanks; you clued me in to the fix. &> seems to be a bash-ism and my fellow DBA had the interpreter set to ksh. If you could tweak you answer to reflect &> being a bash-ism and that 2>&1 works more portably, I'll set it as the answer. –  Rob Sep 17 '13 at 18:31
add comment

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.