sh (line parsing) went that-a-way???

Brandon Allbery allbery at ncoast.UUCP
Tue Jan 14 12:04:07 AEST 1986


Expires:

Quoted from <14363 at rochester.UUCP> ["Re: Redirection quirks: 2>&1 >file  -- vs. --  >file 2>&1"], by ken at rochester.UUCP (Ipse dixit)...
+---------------
| ->> cat d.c
| main()
| {
| 	printf("Hello world\n");
| 	if (open("/etc/phones", 2) < 0)
| 		perror("/etc/phones");
| }
| ->> a.out 2>&1 > xxx
| /etc/phones: No such file or directory
| ->> cat xxx
| Hello world
| ->> a.out > xxx 2>&1
| ->> cat xxx
| /etc/phones: No such file or directory
| Hello world
| ->> 2>&1 a.out > xxx
| ->> cat xxx
| /etc/phones: No such file or directory
| Hello world
| ->> 
+---------------

As cribbed from debugging a locally-modified calendar(1):  (I hope this one
piece of code doesn't get me into licensing trouble!  :-)

	% cat test1
	eval x=foo y=bar
	echo baz
	% sh -x test1
	y=bar x=foo		<=- ...swapped???...
	+ echo baz
	baz
	%

Apparently the shell parses at least part of the command string *backwards*.
But since "2>&1 >foo" and ">foo 2>&1" work as if it were parsed forward, I
don't know where the change in direction occurs.  (And since we don't have
sources, I can't check...)  Times like this make me think TOPS-20 is heaven!
(:-)

--Brandon
-- 
	From the Heart of the Golden Apple...

..decvax!cwruecmp!ncoast!tdi2!brandon (cwruecmp is Case.CSNET, O ye Arpanauts)
(..ncoast!tdi2!root for business)     6615 Center St. #A1-105, Mentor, OH 44060
Phone: +01 216 974 9210      CIS 74106,1032       MCI MAIL BALLBERY (part-time)



More information about the Comp.unix.wizards mailing list