What does the ampersand indicate in this bash command 1>&2

2>&1 redirects standard error (file handle 2) to the same file that standard output (file handle 1) is currently going to.

It’s also a position-dependent thing so:

prog >x 2>&1 >y

will actually send standard error to x and standard output to y as follows:

  • Connect standard output to x;
  • Then connect standard error to same as current standard output, which is x;
  • Then connect standard output to y;

Leave a Comment