forsyth@minster.UUCP (forsyth) (03/11/86)
panda!fluffy!keith complained that the following failed in a version of csh: cat /etc/passwd | (cat) & If he has the csh source (I haven't), I think he will find that it is actually a bug derived from 6th Edition shell(!), and that csh has borrowed some of the older shell's methods, if not its code. The following explanation based on the 6th Edition source might help to find it in csh. In the function `execute', there is code that handles parenthesised commands: those with tree type TPAR. The code propagates the flag FINT, which controls suppression of signals, to the descendent of TPAR that describes the parenthesised command, before a recursive call to execute that command: if(t[DTYP] == TPAR) { if(t1 = t[DSPR]) t1[DFLG] =| f&FINT; execute(t1); exit(255); } Fine, but it should also include FPIN, which states that input should be taken from a pipe. The f&FINT should be f&(FINT|FPAR). Otherwise the following code to handle `&' will close the standard input and open /dev/null, since FPIN will not be set: if((f&FINT)!=0 && t[DLEF]==0 && (f&FPIN)==0) { close(0); open("/dev/null", 0); } This code implements the convention that command& will receive /dev/null as standard input by default, to prevent it stealing terminal input. This might well be different in csh owing to job control. Csh will also undoubtably use structure references instead of array references like t[DLEF]! A copy of the old shell was in /usr/src/cmd/osh.c on 7th Edition systems. Just for fun, I compiled it on a VAX for a PDP-11, and it runs quite happily in PDP-11 compatibility mode, except of course for % echo * glob: cannot execute % $ size11 bin/v6sh 5080+700+1396 = 7176b = 0x1c08b It's amazing what can be done in 7k (it doesn't grow), with 844 lines of code which even includes a few comments (but don't press your luck). ukc!minster!forsyth PS. net.bugs.v6??