Xref: utzoo comp.bugs.4bsd:1330 comp.unix.wizards:17212 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.bugs.4bsd,comp.unix.wizards Subject: Re: csh problem involving nested ifs? Keywords: csh, bug, nested if Message-ID: <18476@mimsy.UUCP> Date: 10 Jul 89 17:30:38 GMT References: <685@wuphys.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 49 In article <685@wuphys.UUCP> marty@wuphys.UUCP (Marty Olevitch) writes: >It appears that csh does not correctly handle nested if-then-else >statements. This is false. It does handle them, but it is finicky. >Am I missing some bug in this script? [all but the `if' lines deleted] >if($v1 == 1) then > if($v2 == 1) then > if($v2 == 1) then You must put a space after the `if', before the `('; and you must have a space between the `)' and the `then' (which must be the last word on the line, after stripping comments). The reason is that the C shell's `skip to end of false construct' code uses a completely different line parser than usual. The `execute this line' parser breaks lines at whitespace and at the characters ( ) & | and perhaps a few others. (&& and || are collected as a unit before causing word breaks.) The `skip to end of false if' routine winds up doing if (strcmp("if(", "if") == 0 && strcmp("then", "then") == 0) in the particular cases given above. Had you written if ($v2 == 1)then it would have tried if (strcmp("if", "if") == 0 && strcmp(")then", "then") == 0) and also failed. Only if ($v2 == 1) then and similar constructs pass its test. (One such construct is if (this, {which is not &syntactically! correct, goes undetected then the c shell sucks endif which counts as an `if-then' during false-if skipping, but causes an error otherwise.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris