cmd - Batch file if statement isn't working as expected - syntax errors? -


so believe i'm having issues syntax in batch file trying write. i'm new writing batch files, , still learning how language works. essentially, have script can run -run , additional commands:

scriptname -run -prereq 

i want able have menu commands can run script:

scriptname -help 

followed more input parameters user wants for

** enter additional input commands script help: 

user input like:

-prereq -one -two -three 

the -run command should run , apply commands.

the -help command should echo information requested commands.

just running script no -run or -help command prints basic header version, time, , explanation -help exists (as seen in code below)

basically, -run should call processes depending on applied, can seen label :process_args similarly, -help first take -help command initiate, , ask more parameters, seen in :help_process_args call labels echo information.

the functionality seems work, if run script no -run parameter, defaults -run functionality. also, keep seeing syntax errors try fix default behavior.

can see why -help works, , why code defaults -run behavior no parameters, instead of printing short header? also, there syntax errors obvious? (again, i'm new batch files)

here's relevant code shows menu creation , calls run , processes.

echo ********************************************* echo ** echo **     script version: x.x echo **         started at: %time% echo **    options use: scriptnamehere -help echo ** echo *********************************************  if /i [%1]==[-help] (     echo **                 options:     echo *********************************************     echo **     echo **      -run   = runs script     echo **   -prereq   = skip prereq steps     echo **      echo ** enter additional input commands script help:     echo **      goto help_input      endlocal     exit /b 0 ) if /i [%1]==[-run] (     call :process_args %*      call :labelone     call :labeltwo     call :labelthree      endlocal     exit /b 0 ) else (     goto end )  :help_input set input= set /p input= ** :  goto help_process  :help_process call :process_help_args %input% if /i not "%_help_opts:-echo=%"=="%_help_opts%" goto:eof  call :helplabelone call :helplabeltwo call :helplabelthree  :process_help_args if %errorlevel% neq 0 exit /b %errorlevel% echo. && echo * setting special arguments     :help_args_loop     if not [%1] equ [] (         if [%_help_opts%] neq [] set _help_opts=%_help_opts%/%1         if [%_help_opts%] equ [] set _help_opts=%1         echo -- found %1         shift         goto help_args_loop     ) else (         if not defined _help_opts (             echo * no options provided             set _help_opts=**empty**         )     ) goto:eof  :process_args if %errorlevel% neq 0 exit /b %errorlevel% echo. && echo * setting special arguments     :args_loop     if not [%1] equ [] (         if [%_opts%] neq [] set _opts=%_opts%/%1         if [%_opts%] equ [] set _opts=%1         echo -- found %1         shift         goto args_loop     ) else (         if not defined _opts (             echo * no options provided             set _opts=**empty**         )     ) goto:eof  :end endlocal echo ** script complete @ %time% exit /b 0 

changing

    endlocal     exit /b 0 ) else (     goto end ) 

to

    endlocal     exit /b 0 ) else (     goto end ) 

produced following results.

c:>labstuff.bat ********************************************* ** **     script version: x.x **         started at: 13:17:55.30 **    options use: scriptnamehere -help ** ********************************************* ** script complete @ 13:17:55.32 

and

c:>labstuff.bat -run ********************************************* ** **     script version: x.x **         started at: 13:16:15.62 **    options use: scriptnamehere -help ** *********************************************  * setting special arguments -- found -run system cannot find batch label specified - labelone system cannot find batch label specified - labeltwo system cannot find batch label specified - labelthree