[comp.os.minix] bourne shell bug

forsyth@minster.york.ac.uk (06/28/91)

in the minix shell, both

for n
do

and

for n; do

both work correctly.  there is a bug, however, since bourne's shell does
(to my surprise) allow
	for n do

part of the trouble with producing a correct bourne shell look-alike
is that there are several special cases in the syntax that don't
appear in the grammar (because the grammar is implemented by
a recursive descent parser with some cases specially programmed).
for instance, tom duff has observed that the grammar does not allow
a common form of pipeline.  the grammar also does not allow the ;;
to be eliminated before the closing esac, although the implementation does.

most of the minix shell was written in 1978
based on bourne's article in the first BSTJ special issue on UNIX.
it was later revised as more accurate /bin/sh documentation appeared,
but undocumentated features could only be added after experience
with the real /bin/sh (eg, by trying to run many shell scripts
on the system, which picked up some differences, such as the ;;/esac one).
the dreaded Configure script didn't exist then.

it was not always clear when reserved word recognition
was to be switched off.  for instance, you'd rightly complain if

	echo done
or
	echo do

gave a syntax error.

after all that, here is a possible fix!  in `case FOR:' in csyn.c,
try replacing the lines

		if ((c = yylex(0)) != '\n' && c != ';')
			SYNTAXERR;

by

		if ((c = yylex(0)) != '\n' && c != ';')
			peeksym = c;

this hasn't been tested much, but that's the advantage of having the source:
you can always undo the change if something breaks!