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
  • 1
    You probably knew this already, but 1 is stdout; 0 is stdin. – Gilles Nov 2 '10 at 18:08
  • the 0 stdin is news to me :) I learnt something +1 – Stefan Nov 2 '10 at 20:36
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.
  • 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 Nov 1 '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 2 '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 Nov 2 '10 at 18:07
  • yeah, that seems pretty much like one of those false memories... – alex Nov 2 '10 at 20:44
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.