Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!hplabs!sri-unix!moss@brl-vld
From: moss%brl-vld@sri-unix.UUCP
Newsgroups: net.unix-wizards
Subject: Re:  nested if's in csh
Message-ID: <17009@sri-arpa.UUCP>
Date: Wed, 29-Feb-84 08:36:24 EST
Article-I.D.: sri-arpa.17009
Posted: Wed Feb 29 08:36:24 1984
Date-Received: Sat, 3-Mar-84 23:03:41 EST
Lines: 41

From:      Gary S Moss ~Software Development Team~ 

> The following shell script, when run with the four permutations of inputs
> t 0 0
> t 1 0
> t 0 1
> t 1 1
> works correctly in all cases.
>
> #! /bin/csh -f
> set a = $1
> set b = $2
> if ( $a ) then
>    if ( $b ) then
>	echo a and b
>    else
>	echo a and not b
>    endif
> else
>    if ( $b ) then
> 	echo not a, but b
>    else
> 	echo neither a nor b
>    endif
> endif
>
> However, if spaces are left out between the "if" and the "(", it no
> longer works correctly. Thus the space appears to be the key. This seems
> to be a bug.

This is not the same situation as Jim presented.   Jim's problem stems
from having a nested 'if' in the 'else' branch of the outside conditional
such that an 'else' is followed immediately by the nested 'if'.
Your example has such a situation :

	else
	    if ( $b ) then ...
	
HOWEVER, even though the bug in the csh syntax makes this ambiguous,
the two possible expressions are functionally equivalent, the alternate
is below.