Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding /? switch in batch?

Tags:

batch-file

Do someone knows how to add the action to be triggered when calling my batch file with the /? argument ? I've always used the -h to display usages, but for once I need my -h arg for something else.

EDIT : Actually I've tried by parsing attributes like this

for %%i in (%*) do ....

But the /? argument was skipped, I'll try yours solutions to see if it's different.

Btw, why when you parse %%i the /? args is skipped ?

like image 677
kitensei Avatar asked Nov 18 '11 08:11

kitensei


1 Answers

The /? seems to be simply skipped by the for %%i in (%*) but it's the wildcard functionality of the for-loop, it tries to find a file that matches /? which will fail.

You can not use ? or * in a "normal" for-loop, without modifying the result.

You could use the SHIFT command to access all your parameters.

:parameterLoop
if "%~1"=="/?" call :help
if "%~1"=="-h" call :help
if "%~1"=="-o" call :other
shift
if not "%~1"=="" goto :parameterLoop

If you also want to display the selected option, you got a problem with the echo command, as this will normally show the help instead of /?.

You can avoid this by using echo(%1 instead of echo %1.

like image 113
jeb Avatar answered Sep 22 '22 22:09

jeb