Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!mhuxm!mhuxf!mhuxi!mhuhk!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP Newsgroups: net.unix-wizards,net.bugs.4bsd Subject: Re: C-Shell weirdness Message-ID: <344@hadron.UUCP> Date: Sat, 29-Mar-86 03:21:00 EST Article-I.D.: hadron.344 Posted: Sat Mar 29 03:21:00 1986 Date-Received: Tue, 1-Apr-86 07:16:13 EST References: <676@nbires.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Distribution: net Organization: Hadron, Inc., Fairfax, VA Lines: 28 Xref: watmath net.unix-wizards:17407 net.bugs.4bsd:2024 Summary: only re: if ($arg == '-b') In article <676@nbires.UUCP> nose@nbires.UUCP (Steve Dunn) writes: > if ($arg == '-b') echo 'UNIX is fun' >Will get the error "If: missing filename" if $arg happens to equal >-x or -e or any of the other constructs used to test file attributes. > if (x$arg == 'x-b') echo 'UNIX is fun' >Is there a better way to do this and why does this happen in the first >place? [The rest of this was ably answered elsewhere. HOWEVER ...] Consider what the command line is when $arg is -e or -x or whatever: if (-e == '-b') ... Now, doesn't that just look like it's asking to evaluate -e on file "==", or something like that? Of course the parser recognises "==" as a relation, and so complains instead that there's no file name. Your alternative is actually a venerable shell-script idiom to cancel the flag effect of the "-". However, you really should put $arg in double-quotes to negate the effect of an in-valid string: set arg = "-b -e" if (x$arg == '-b') becomes if (x-b -e == '-b') with who knows what syntax error reports. I'd use: if ("X$arg" == "X-b") ... -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}