Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!phigate!ehviea!sun4dts!derek From: derek@sun4dts.dts.ine.philips.nl (derek) Newsgroups: comp.os.msdos.misc Subject: Re: Getting rid of "syntax error" from .bat files - how to? Message-ID: <635@sun4dts.dts.ine.philips.nl> Date: 6 Dec 90 09:54:38 GMT References: <9467@pasteur.Berkeley.EDU> <5649@uafhp.uark.edu> Lines: 42 sab@engr.uark.edu (Steven A. Breuer) writes: >In article <9467@pasteur.Berkeley.EDU>, brand@cad.Berkeley.EDU (Graham Brand) writes: >> I have written a batch file which accepts parameters from the command >> line using the: >> if %1==param1 >> syntax. It works fine except that if I don't pass any parameters, I >> get the above syntax error message. Is there any way to suppress this? >> >> In addition, is there any way of passing a string, the first character >> of which is a dash (-), as in -f? It doesn't seem to work with the >> above test. >> > Batch files have trouble with blank parameters (none). try the > following "if" statements. It is a good idea to surround the parameters > with some character - this should take of errors happening because > of no parameters. This should also allow you to use the dash (-) as > part of a parameter. > if "%1"=="" goto NOPARMS > if "%1"=="param1" goto PARAM1 > Steve Breuer > sab@engr.uark.edu You can also use the following trick that I often use: if "%1"=="" goto NOPARMS goto %1 rem here handle incorrect parameters. The "goto %1" branches to the label passed as parameter 1. This is especially useful in a batch file calling itself. (Think about it!) Best Regards, Derek Carr DEREK@DTS.INE.PHILIPS.NL Philips I&E TQV-5 Eindhoven, The Netherlands Standard Disclaimers apply.