Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given the preamble, foobar function and invocations of it:

exec 3>/dev/null    
function foobar { echo foo; echo bar >&2; }
foobar >/dev/null
foobar 2>/dev/null
foobar &>/dev/null
foobar &>&3

Why doesn't the last simple command get executed by Bash? Instead Bash quits with:

-bash: syntax error near unexpected token `&'
share|improve this question
up vote 4 down vote accepted

That's because there is no operator &>&.

There is an operator &> word that redirects both stdout and stderr to word.

There is an operator [n]>& word that duplicates fd n (default 1) from fd word. As a special case, if n is empty, and word isn't a number, redirects both stdout and stderr to word.

But that's it. There isn't a special syntax for file descriptors which you can combine with operators. There are just the operators, which can interpret their operands as file descriptors or filenames. And there isn't a &>& operator which redirects both stdout and stderr, and interprets its right operand as a file descriptor.

Summary: There is no special syntax &n for file descriptors. The & belongs to the operator, not to the operand. There is no operator &>&.

share|improve this answer

And why would it? "... &>file" is just a syntactic sugar for "... >file 2>&1". Nothing more. If you want to make descriptor 2 point where 3 is pointing (/dev/null), you need to use "... 2>&3".

share|improve this answer

Your Answer


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.