Remove yet more bashisms, other shell fixes and improvements.