[alt.sys.sun] a few bugs in the Bourne shell of SunOS 4.0.3c and 4.1.1

maart@cs.vu.nl (Maarten Litmaath) (02/02/91)

Note: followups to comp.unix.shell,alt.sys.sun.

The following 1-line command makes sh dump core (just be patient):

	cat << `date`

The following function definition is handled incorrectly:

	say(){
		cat <<- EOF
		$*
		EOF
	}

The body of any function must _only_ be evaluated when the function is
_invoked_, not when it is _defined_.  That sh fails in the example can
be shown as follows:

	set | sed '/^say(/,/^}$/!d'

This will print something like this (without indentation):

	say(){
	cat 0<</tmp/sh10890
	}

It is clear what happens (though the syntax of the `translated'
function is strange, to say the least).  It even works (!),
_as_long_as_ the temporary file /tmp/sh10890 isn't changed or deleted.

Whatever, the function body should have been left unchanged or
translated to a _really_ equivalent (canonical) form.

Workaround:

	say(){
		eval 'cat <<- EOF
		$*
		EOF'
	}

Right, the last bug concerns the order in which assignments are
performed:

	foo=x
	bar=$foo foo=y
	echo $bar

This will print:

	y

Assignments must be performed left to right though (`beginning to
end', as POSIX 1003.2 would say), so $bar should have been `x'.
--
"Salman Rushdie received a copy just as his latest novel was being published.
He ignored it and received myriads of death threats. He quickly decided to
send out twenty copies (some to the Ayatollah) and is still alive."
			(John Banagan <jvbanagan@ucdavis.edu> in sci.skeptic)