How does man know?
A.V. Raman
ARaman at massey.ac.nz
Wed Sep 27 10:38:44 AEST 1989
How does man know?
------------------
(This article is not cross posted to talk.philosophy.misc)
Synopsis:
~~~~~~~~~
What is the difference between
$ man sh
and
$ man sh | grep -i chdir
as far as man is concerned
When I do a man sh, I have to page down a few times or /search
to get to the page where chdir, for example, is discussed.
However when I pipe the output of man into another command or
redirect it into a file, man seems to somehow sense that it is now
writing into a pipe rather than into a terminal because it does
not pause after each screenful asking for keyboard input.
This is quite perplexing because it goes against the basic philosophy
of transparency in UNIX, as it is the shell that is supposed to handle
such things as pipes and redirections. Theoretically and ideally,
man, more, or other such things should never get to know where their
output is physically going.
My guess is that when shell forks and execs man, it passes down the
file descriptor of stdin and stdout, which however, are now different
from the actual stdin and stdout and man uses (stdout->_file == 1)?
to determine whether the output is a tty or not (yuck). But it does
seem to be very convenient though.
Am I right?
Morals of the story:
~~~~~~~~~~~~~~~~~~~~
1. Man may not always know everything that one asks for; but he
sure knows somethings that sometimes none asks for.
2. Man does learn from dad sometimes
--
/*----------------------------------------------------------------------*/
Anand Venkataraman - Systems group, Computer Center, Massey University,
Palmerston North, New Zealand
INTERNET: A.Raman at massey.ac.nz Ph: +64-63-69099 x7943 NZ = GMT + 12
More information about the Comp.unix.questions
mailing list