read/write I/O redirection for sh

Brian Horn lcc.brian at UCLA-LOCUS.ARPA
Wed May 22 19:45:24 AEST 1985


	A while ago someone asked what the redirection syntax "<>" was
for and whether it was useful.	Since it didn't work, it certainly wasn't
useful, however the fix below may be found to be useful (Note: this patch
is for the bourne shell distributed with sysV release 2.  It should be
very similiar for other versions of sh.)


sh/service.c (approx. line 65)
		    .
		    .
		    .
	    else if (iof & IOMOV)
	    {
		    if (eq(minus, ion))
		    {
			    fd = -1;
			    close(ioufd);
		    }
		    else if ((fd = stoi(ion)) >= USERIO)
			    failed(ion, badfile);
		    else
			    fd = dup(fd);
	    }
+	    else if (iof & IORDW) {
+		    if ((fd = open(ion, 2)) < 0)
+			    failed(ion, badopen);
+	    }
	    else if ((iof & IOPUT) == 0)
		    fd = chkopen(ion);
			.
			.
			.

This patch will open the file after the "<>" read/write defaulting to
file descriptor 0. (Of course, as with all sh redirection you may proceed
it with a file descriptor number.)

Brian D. Horn
Locus Computing Corporation			       lcc!brian at ucla-cs
					{ucivax,trwrb}!lcc!brian
	 {ihnp4,randvax,sdcrdcf,ucbvax,trwspp}!ucla-cs!lcc!brian



More information about the Comp.unix.wizards mailing list