Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site sdchema.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxr!ulysses!allegra!bellcore!decvax!ittvax!dcdwest!sdcsvax!sdcc3!sdchema!jwp From: jwp@sdchema.UUCP (John Pierce) Newsgroups: net.unix-wizards Subject: Re: Yet even MORE Csh Quirks Message-ID: <369@sdchema.UUCP> Date: Fri, 19-Apr-85 19:22:28 EST Article-I.D.: sdchema.369 Posted: Fri Apr 19 19:22:28 1985 Date-Received: Sun, 21-Apr-85 23:49:13 EST References: <10032@brl-tgr.ARPA> Reply-To: jwp@sdchema.UUCP (John Pierce) Organization: Chemistry Dept, UC San Diego Lines: 79 In article <10032@brl-tgr.ARPA> argv@ucb-vax.ARPA writes: > ... It seems that "endif"'s don't know who they are ending. Exibit A: > #!/bin/csh -f > @ count = 0 > if($#argv == 2) then > echo hi there > if( 1 ) then # this statement if obviously a no-op. > @ count++ # count should be 1 > echo true > endif > echo hi there again > @ count++ # count should be 2 > endif > echo count = $count > > if argv is NOT 2, then $count should be 0, right?! > else count should be 2... but in ANY event, count > should NEVER be 1. Also, you should either see, > "hi there" AND "hi there again" or NEITHER, am I right? No, not really. > The fault lies in the fact that you can't have nested if statements.... You can have nested 'if' statements. The "fault" lies in a syntax error. The two 'if' statements should be if ($#argv == 2) and if (1) While it is annoying, that space between 'f' and '(' is necessary for csh to handle the statement properly [the manual entry *does* specify "if (expr)..."]. It is also the case that if (expr1) then stmt1 else if (expr2) then stmt2 endif is handled differently from if (expr1) then stmt1 else if (expr2) then # Syntax specified by the manual stmt2 endif when either the "if" portion or the "else" portion contains further "if" statements. I believe, though it's been a long time since I tested all of this, that there are also problems with "while" and "foreach" inside improperly typed "if" statements. I do remember that while(expr) ... while(expr) ... end ... end (and the equivalent "foreach") also break, since the specified syntax is while (expr) foreach (expr) I have forgotten whether or not the space is absolutely necessary in "switch" statements, but I believe it is. While having to have the space there seems dumb, with it things work as you would expect; without it, they do not. The problem can be fixed in the source, though it isn't completely trivial [meaning it didn't seem to be sufficiently trivial for me to waste time on a problem that doesn't annoy me any more than this one does]. John Pierce, Chemistry, UC San Diego {sdcsvax,decvax}!sdchema!jwp jwp@ucsd