I just want to leave a reminder about the %~ symbol combination, but my running my batch file outputs this:
C:\Users\batch\batch>add_one2The following usage of the path operator in batch-parameter
substitution is invalid: %~n' is passed argument
For valid formats type CALL /? or FOR /?
C:\Users\batch\batch>
Here's the script:
@echo off
REM '%~n' is passed argument
goto :main
:add_one
setlocal
echo Running 'add_one'...
endlocal & set /a %~1=%~2+1
goto :eof
:main
setlocal
set /a x=1
set /a y=50
echo Created variable X and set it to %x%
echo.
call :add_one y %y%
echo.
echo The value of X is now %x%
endlocal
goto :eof
I tried ::, REM, and escaping in quotes, but it didn't work either.
REM "%~n" is passed argumentecho.to output a blank line as that results always in a file system access bycmd.exesearching in the current directory for a file with nameecho. See Different echo?... variants with a very good and detailed information what is much better for the output of a blank line thanecho.likeecho/orecho(and what are their pros and cons.