Bourne Shell bug? Have a look..

mike at bria mike at bria
Mon Jan 28 07:15:19 AEST 1991


In article <1067 at mwtech.UUCP> martin at 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 ..."



More information about the Comp.unix.shell mailing list