Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool2.mu.edu!uunet!bria!mike From: mike@bria Newsgroups: comp.unix.shell Subject: Re: Bourne Shell bug? Have a look.. Message-ID: <400@bria> Date: 27 Jan 91 20:15:19 GMT References: <1174@otello.sublink.org> <1991Jan16.152933.7288@usenet.ins.cwru.edu> <1991Jan16.153557.15548@ms.uky.edu> <1067@mwtech.UUCP> Reply-To: uunet!bria!mike (Michael Stefanik) Organization: Briareus Corporation, Los Angeles, CA Lines: 37 In article <1067@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: >You further know (or again you just learn it), that there can be more >than one redirection per line: > > echo hello >file foo >baz > >Now: Which redirection is the one that is finally in effect when the >programm (the `echo' in the above example) runs, if you combine both >of the above "strange" ways to do I/O-direction? (What I want is not >the answer to a specific example, but the general rule!) I'll post the >answer in a week or so if noone solves this). I must admit that I was suprised a bit. I would have guessed that 'file' would be empty, and 'baz' contain "hello foo", when it's really the other way around. I thought the logic would have been: open 'file' for O_WRONLY|O_TRUNC|O_CREAT dup stdout dup2 file descriptor to stdout since stdout is a file ... dup2 duplicated stdout descriptor to stdout open 'baz' for O_WRONLY|O_TRUNC|O_CREAT dup stdout dup2 file descriptor to stdout (which would close file) Does the shell just close the subsequent files it opens when it discovers that stdout is not a tty? IMHO, the shell should issue an error if redirection is specified for the same descriptor more than once, but I suppose that there are those who adore this particular feature ... -- Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation UUCP: ...!uunet!bria!mike -- technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly found to be saying things like "Well, it works on my DOS machine ..."