Newsgroups: comp.unix.shell Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Subject: Re: When is an expression "true"? Message-ID: <1991May9.010320.14968@athena.mit.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology References: <1991May8.173342.2514@aucs.AcadiaU.ca> Distribution: na Date: Thu, 9 May 91 01:03:20 GMT Lines: 40 The csh man page does not document the ability to have if statements without parentheses around the boolean expression, and it is *not* something you should rely on, because it is not supported and will break much of the time. In the particular example you gave: set f=`ls` if $#f > 1 then ... endif breaks because the shell notices the '>' and assumes that it is redirection rather than a numerical comparison. I suspect there's a file called "1" in the directory in which you ran this shell script. I should probably mention that parentheses aren't the only thing you can use -- you can also use curly braces, which cause a csh if statment to function much the same way the bourne shell's if statement functions. This: foo if ($status == 0) then ... endif is equivalent to this: if { foo } then ... endif This is a useful feature whose documentation is unfortunately buried deep in the man page for csh, and is only mentioned in passing -- "Also available in expressions as primitive operands are command executions enclosed in `{' and `}'..." Of course, it never explains what "command executions" are. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710