Path: utzoo!attcan!uunet!midway!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.shell Subject: Re: Help needed with conditional statement for alias in csh Message-ID: <26553@mimsy.umd.edu> Date: 14 Sep 90 15:24:25 GMT References: <6929.26ed0b53@uwovax.uwo.ca> <6932.26ed237f@uwovax.uwo.ca> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 60 In article <6932.26ed237f@uwovax.uwo.ca> miller@uwovax.uwo.ca (Greg Miller) writes: >Followup-To: j g miller (No wonder there have been no followups. None of `j', `g', `miller', or `' are valid newsgroup names....) >if ( { test -s /usr/spool/mail/miller } ) then; echo "" ; echo "New mail" ;\ > echo "" ; endif >If the file is present, the condition is met and the statements are >executed. > >If the file is zero length, the condition is not true, then >the sequence of commands are not executed but the if statement >is not terminated. Correct. >Any ideas on why this bizarre behavior This is the C shell we are talking about. Do not expect anything resembling sanity. >and how to get it to work properly? Do not use an alias. The C shell's `parser' looks for a *line* whose first word is `else' or `endif' after the C shell executes a false `if (expr) then'. While scanning for such a line it notes lines that have the form if.*then and increments a `false if' counter. You can thus stick all sorts of syntactic trash between a false `if' and its corresponding `endif'; only when the test in the `if' becomes true will the C shell actually notice that the trash is indeed invalid. For instance: if (0) then if (look, unclosed { and !funny characters then endif echo this does not get echoed endif echo but this does It *is* possible to jam a newline into an alias, but if you do you will quickly run afoul of other C shell bugs. For instance: % alias t 'if (0) then\ echo foo\ endif\ echo bar' % t ? ? % Nothing gets echoed. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris