csh question - (nf)

fair at dual.UUCP fair at dual.UUCP
Wed Feb 29 13:04:43 AEST 1984


[RAID]
	I'm having trouble with nesting of csh "if-else-endif". In the following

    ----------------------
    #! /bin/csh				{
    set x=1				    x=1;
    if($x == 1) then			    if(x == 1){
	    set y=2			        y=2;
    else				    }else{
	    if($y == 2) then		        if(y == 2){
		    echo "line 1"		    printf("line 1");
	    else			        }else{
		    echo "line 2"		    printf("line 2");
	    endif			        }
	    echo "shouldn't get here"	    printf("shouldn't get here");
    endif				    }
    echo "finished"			printf("finished");
					}
    ----------------------

You problem is due to the fact that only one 'endif' is needed.  The 
documentation on the csh states:

	if (expr) then
		....
	else if (expr2) then
		....
	else
		....
	endif

	Any number of else-if pairs are possible; only one endif is needed.


	Richard McNeal
UUCP:	{sri-unix,amd70,hpda,harpo,ihnp4,allegra}!fortune!mcneal
DDD:	(415)595-8444
USPS:	Fortune Systems Corp, 101 Twin Dolphins Drive, Redwood City, CA 94065
----

It should also be noted that csh is particular about spacing, so there should
be a space between the `if' and the first paren. I believe there was even a
bug associated with nested if's in Csh reported some time back...

	Erik E. Fair

	dual!fair at BERKELEY.ARPA
	{ihnp4,ucbvax,cbosgd,decwrl,amd70,fortune,zehntel}!dual!fair
	Dual Systems Corporation, Berkeley, California



More information about the Comp.unix.wizards mailing list