0

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.

1 Answer 1

4

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.

1
  • 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, 2013 at 18:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .