Bash – How does file descriptor re-assigment work

bashfile-descriptors

In a way this question is a extension of another question.

In bash you can do pretty neat stuff with file descriptors. Like

{ command > /dev/null } 2>&1 | grep filter;

to grep on stderr only.

My Question[s]:

  • How many levels of descriptors are there. ( How high can the "numbers" go) ?
  • Appart from 1 and 2 ( which are stdout and stderr ), what is the meaning and general use of those other "numbers"?
  • Is the order in which they are specified important?
    e.g. command 1>&2 3>&1 2>&3 versus command 2>&3 3>&1 1>&2

Best Answer

  • You may well expect them to go up to 63 on a typical Linux box.
  • There is (was?) stdlog, but it's rarely used (I believe I never saw one).
  • The order is important: check man bash REDIRECTION.