.BAT Switches Parsing

Posted by giiYanJ on Stack Overflow See other posts from Stack Overflow or by giiYanJ
Published on 2012-12-01T03:23:29Z Indexed on 2012/12/02 5:04 UTC
Read the original article Hit count: 120

Filed under:
|
|
|

Erm.. I'm working with a switches parsing in BAT files, which goes like this:

<commands> -a -b -x -y -z -u abc ......

The user may input a lot of switch, or none. So I used looped shift to make parsing infinite switches possible:

:loop
IF "%1"=="-a"
...
SHIFT
GOTO loop

But when the script ends, I always get cmd executing the switches and showing up error like

'-n' is not recognized as an internal...

So, someone got any idea? Thanks a lot... P/S: Make solution sticks with BAT script if possible as using other language may cause dependencies problem as this script is aimed on ANY computer with Windows.

Finally, thanks again =)

EDIT: Tried shf301 suggestion, i found out that I used DEL %0 to delete itself but it seems the %0 is shifted into the arguments because of the SHIFT command.

© Stack Overflow or respective owner

Related posts about batch-file

Related posts about cmd