Use of && and || in sh / csh

Guy Harris guy at sun.uucp
Thu May 9 17:14:47 AEST 1985


> I have a problem with the Unisoft 2.4 on my Wicat which does not
> appear under 4.2 -- the sense of && and || are reversed when run
> under csh.  ... Is this a unique bug in Unisoft Unix, or is there a
> rationale to the difference?

It's a bug; I don't know if it's unique to Unisoft UNIX or (as I suspect)
it's common to all "csh"s that are derived from a pre-4.1BSD version.

The code with the problem is from "sh.sem.c"; it should look something like
this:

	case TOR:
	case TAND:
		if (t->t_dcar) {
			t->t_dcar->t_dflg |= t->t_dflg & FINT;
			execute(t->t_dcar, wanttty);
			if ((getn(value("status")) == 0) != (t->t_dtyp == TAND))
				return;
		}
		if (t->t_dcdr) {
			t->t_dcdr->t_dflg |= t->t_dflg & (FPAR|FINT);
			execute(t->t_dcdr, wanttty);
		}
		break;

If I remember correctly, the bug is that the comparison operator comparing
the two boolean expressions in the line with 'value("status")' in it is an
==, rather than a !=.  Either that, or one of the "=="s was an "!=".  (The
author probably forgot that the shell convention for "true" and "false" was
that "true" was 0 and "false" was non-zero).

	Guy Harris



More information about the Comp.sources.bugs mailing list