Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site decwrl.UUCP Path: utzoo!watmath!clyde!floyd!harpo!decvax!decwrl!daemon From: daemon@decwrl.UUCP Newsgroups: net.unix-wizards Subject: Re: re: csh question; a possible explanation Message-ID: <6006@decwrl.UUCP> Date: Fri, 2-Mar-84 15:11:55 EST Article-I.D.: decwrl.6006 Posted: Fri Mar 2 15:11:55 1984 Date-Received: Sat, 3-Mar-84 23:47:33 EST Sender: daemon@decwrl.UUCP Organization: DEC Western Research Lab, Los Altos, CA Lines: 31 From: logic::puder (Karl Puder DTN 225-4979) wivax!evans message of 29-Feb-1984 09:07:50, Re: re: csh question indicates that adding a space after the ifs below (s|if(|if (|g) will prevent the incorrect behavior. My (possibly correct) explanation follows. #! /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"); } What happens is this: the first 'if' finds a true condition, and so "set y=2" is executed. Then the 'else' tells csh to "skip statements until you see an endif". The problem is that the "skip until endif" code does not notice the second 'if' unless it is followed by a space, so the wrong 'endif' gets matched. Why didn't Bill Joy use Lex and/or Yacc?!! One beauty of UNIX is that there are all these great tools for writing programs. USE THEM! Karl Puder DEC AITG (617)568-4979 ...!decwrl!rhea!logic!puder