Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ccivax.UUCP Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!houxz!vax135!floyd!cmcl2!seismo!rochester!ritcv!ccivax!crp From: crp@ccivax.UUCP (Chuck Privitera) Newsgroups: net.bugs.4bsd Subject: Re: Ioctl Errors Message-ID: <157@ccivax.UUCP> Date: Tue, 12-Jun-84 12:47:02 EDT Article-I.D.: ccivax.157 Posted: Tue Jun 12 12:47:02 1984 Date-Received: Wed, 13-Jun-84 02:23:16 EDT Organization: CCI Telephony Systems Group, Roch, NY Lines: 45 I have seen some very bizarre things happen in C-shell scripts due to a bug in parsing if statements. In the manual it outlines the syntax of if to be: if(expr) command or if(expr) then ... else if(expr2) then ... else ... endif Notice that the example shows no space between the if and the opening paren. Now, in C, bc, awk, etc., a space between if and the opening paren is optional, in the C-shell, if you don't have a space there nested ifs break. Here is an example that shows the problem: #!/bin/csh -f if ( $?a ) then echo the variable a is set if( $?b ) then echo the variable b is set else if ( $?c ) then echo the variable c is set else echo a is set but b nor c are. endif else echo a is not even set endif If you run this without setting a variable a or b or c, the output will be "a is set but b nor c are." . The first if is matching the first else! The problem is that the second if, i.e. if( $?b ), needs a space between if and the left paren. Obvious isn't it!!! I haven't bothered to chase the problem down I don't usually write shell scripts in C-shell. I think I first ran into this in my .cshrc file. Anyways, C-shell programmers beware this one. Chuck Privitera, Computer Consoles Inc. {allegra,seismo}!rochester!ritcv!ccivax!crp