我需要测试是否设置了变量.我已经尝试了几种技术,但他们忽视了,只要%1用双引号包围时,如情况%1是"c:\some path with spaces".
IF NOT %1 GOTO MyLabel // This is invalid syntax
IF "%1" == "" GOTO MyLabel // Works unless %1 has double quotes which fatally kills bat execution
IF %1 == GOTO MyLabel // Gives an unexpected GOTO error.
Run Code Online (Sandbox Code Playgroud)
根据此站点,这些是受支持的IF语法类型.所以,我没有办法做到这一点.
IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
Run Code Online (Sandbox Code Playgroud) 回到90年代中期,我记得做过这样的事情:
if %1==. dir
Run Code Online (Sandbox Code Playgroud)
基本上,如果你把上面的代码放在dodir.bat并自己运行而不传递任何参数,它将运行dir命令.但是,如果您将任何内容作为参数传递给它,它将不会运行dir命令.
我似乎无法在我的Windows 7批处理文件中使用它.也许我不记得正确的语法.有帮助吗?
我试图在屏幕上显示最多9个参数,然后在每个后续行显示少一个参数,直到没有剩下.
我试过这个:
@echo off
echo %*
shift
echo %*
shift
echo %*
Run Code Online (Sandbox Code Playgroud)
实际结果:
a b c d e f
a b c d e f
Run Code Online (Sandbox Code Playgroud)
预期结果:
A B C D E F
B C D E F
C D E F
D E F
E F
F
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
谢谢.