I wish to write a Windows Batch script that first tests to see if any of the command line arguments are equal to /?. If so, it displays the help message and terminates, otherwise it executes the rest of the script code. I have tried the following:
@echo off
FOR %%A IN (%*) DO (
IF "%%A" == "/?" (
ECHO This is the help message
GOTO:EOF
)
)
ECHO This is the rest of the script
This doesn’t seem to work. If I change the script to:
@echo off
FOR %%A IN (%*) DO (
ECHO %%A
)
ECHO This is the rest of the script
and call it as testif.bat arg1 /? arg2 I get the following output:
arg1
arg2
This is the rest of the script
The FOR loop appears be ignoring the /? argument. Can anyone suggest an approach to this problem that works?
Something like this should do the trick:
Thanks to @jeb for pointing out the error if only /? arg provided