C:\_G\WWW\~ELISANET\INFO\tscmd093.html
<http://www.elisanet.fi/tsalmi/info/tscmd093.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Fri 30-Nov-2018 11:37:47

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



93} How do I check if my script was given a parameter?

Back to the very basics, with some additions. The most common test for detecting if any batch parameters are given is
  @echo off & setlocal enableextensions
  if not "%~1"=="" echo.%~1
  endlocal & goto :EOF

For example one might have
  C:\_D\TEST>cmdfaq "a b"
  a b
or
  C:\_D\TEST>cmdfaq "^&^(^)[]{}^^=;!'+,`~^<^>"
  &()[]{}^=;!'+,`~<>

If we omit the ~ modifier which removes any surrounding quotation marks ("") we might have e.g.
  @echo off & setlocal enableextensions
  if not "%1"=="" echo.%1
  endlocal & goto :EOF

  C:\_D\TEST>cmdfaq "a b"
  b""=="" was unexpected at this time.
or
  C:\_D\TEST>cmdfaq "a" "b"
  "a"

However,
  @echo off & setlocal enableextensions
  set par1=%1
  if defined par1 echo %1
  endlocal & goto :EOF

  C:\_D\TEST>cmdfaq "a b"
  "a b"

It is obvious that one has to be mindful of the quotes and the usage of the ~ modifier.

For more on parsing the parameters, see e.g. item #40.

References/Comments: (If a Google message link fails try the links within the brackets.)
  hh ntcmds.chm::/percent.htm [You can't use this unless you have the ntcmds.chm file]
  Google Groups Sep 14 2005, 1:26 am [M]
  Google Groups Apr 13 2006, 8:10 pm [M]

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd093.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd093
http://www.elisanet.fi/tsalmi/info/tscmd093.html
file:///c:/_g/www/~elisanet/info/tscmd093.html