4

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
Stefan
  • 25,300

2 Answers2

2
  • 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.
alex
  • 7,223
  • I don't think there's anything standard about 3 going to syslog, it just happens to be the first opened by many programs that already have the standard 0, 1, 2 open. – Gilles 'SO- stop being evil' Nov 01 '10 at 18:21
  • @Gilles: actually I was talking about stdlog, not syslog. Too bad, it's not easy to find something viable about that. I believe it was obsoleted long ago. And I must be wrong for putting 3 as it's default number... :-P – alex Nov 02 '10 at 10:13
  • From light googling, stdlog might have been a FORTRAN thing that never made it into Unix. I didn't find anything like a reference for this, though. – Gilles 'SO- stop being evil' Nov 02 '10 at 18:07
  • yeah, that seems pretty much like one of those false memories... – alex Nov 02 '10 at 20:44
1

The number you need is given by the maximum file descriptor count from the ulimit(1) command.