2

In Ksh for redirecting i/o from a command away from standard output/error I do , [ where command is any command that produces output/error ]

command 2>filename
command 2>/dev/null

or

command &>filename
command &>/dev/null

In bash , often I see code like

command >&/dev/null

what does that additional & signify, when the same can be get done by using

command> /dev/null

I know I am missing something fine, but glad to learn.

EDIT: I knew what 2>&1 is, which the so called duplicate question asks , I was told that 1 indicates a file descriptor and hence we need an & to refer that. I was puzzled to see & before the name of the file. Hence this question.

1 Answers1

2
>&fname

is the same as

>fname 2>&1

i.e. it redirects both stdout and stderr into file fname. See bash(1) man page, section REDIRECTION (especially its part Redirecting Output) for detailed explanation.

peterph
  • 30,838
  • awesome. wondering why the documentation says out of &>fname and >&fname , the former is preferred. Thanks a lot of pointing me to the right documentation. – user917279 Sep 25 '13 at 15:05
  • That documented preference puzzles me too. When csh introduced the >& syntax it had to be in that order because the parser wasn't as complicated and ls &> junk.dat was semantically equivalent to ls & ; cat /dev/null > junk.dat. For the benefit of a reader of a script, I'd still use >& to lessen the ambiguity, but I'm pretty old skool. – msw Sep 25 '13 at 16:29
  • http://unix.stackexchange.com/a/89388/20291 points to a nice article on redirection. – user917279 Sep 26 '13 at 07:49