XP script (cmd) check several variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I check several variables with a if statement?

if NOT "%1" == "" goto WHATEVER
this works fine, but how can I check several variables like if %1 AND %2??

Basically I like to check if %1 and %2 is set, otherwise print help and exit
:-)
 
AeS said:
How can I check several variables with a if statement?

if NOT "%1" == "" goto WHATEVER
this works fine, but how can I check several variables like if %1 AND %2??

Basically I like to check if %1 and %2 is set, otherwise print help and exit
:-)]

Try this:

if not "%1"=="" if not "%2%=="" goto . . .

Keep in mind that the above line is logically equivalent to

if not "%2"=="" goto
 
AeS said:
How can I check several variables with a if statement?

if NOT "%1" == "" goto WHATEVER
this works fine, but how can I check several variables like if %1 AND %2??

Basically I like to check if %1 and %2 is set, otherwise print help and
exit
:-)

if NOT "%1" == "" goto WHATEVER
if NOT "%2" == "" goto WHATEVER

:HELPANDEXIT
echo help
goto :eof

:WHATEVER
echo ok


Jon
 
oops .. answered too quickly

if %1 == "" goto HELPANDEXIT
if %2== "" goto HELPANDEXIT


:WHATEVER
echo ok
goto :eof

:HELPANDEXIT
echo help
goto :eof

Jon
 
This code will fail when %1 or %2 are blank.


Jon said:
oops .. answered too quickly

if %1 == "" goto HELPANDEXIT
if %2== "" goto HELPANDEXIT


:WHATEVER
echo ok
goto :eof

:HELPANDEXIT
echo help
goto :eof

Jon
 
Yes, very true.. should have been....

@echo off

if "%1"=="" goto :HELPANDEXIT
if "%2"=="" goto :HELPANDEXIT


:WHATEVER
echo ok
goto :eof

:HELPANDEXIT
echo help
goto :eof

Jon
 
Back
Top