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.