Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!munnari.oz.au!comp.vuw.ac.nz!massey!ARaman From: ARaman@massey.ac.nz (A.V. Raman) Newsgroups: comp.unix.questions Subject: How does man know? Keywords: more, io redirection Message-ID: <319@massey.ac.nz> Date: 27 Sep 89 00:38:44 GMT Reply-To: ARaman@massey.ac.nz (A.V. Raman) Organization: Massey University, Palmerston North, New Zealand Lines: 45 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@massey.ac.nz Ph: +64-63-69099 x7943 NZ = GMT + 12