Bla*_*lle 2 function batch-file
我想将一堆布尔标志传递给Windows批处理脚本函数.像这样的东西:
1 SETLOCAL
2 SET _debug=1
3 SET _x64=1
4
5 call :COMPILE %_debug% %_x64%
6 :: call again where %_debug% is now 0
7 :: call again where %_x64% is now 0
8 :: etc...
9
10 :COMPILE
11 :: stuff depending on input args
Run Code Online (Sandbox Code Playgroud)
我使用的变量_debug,并_x64打的电话(线5-7)更具可读性,而不是像这样:
call :COMPILE 0 1
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来传递相当于not variable?喜欢:
call :COMPILE ~%_debug% ~%_64%
Run Code Online (Sandbox Code Playgroud)
要么
call :COMPILE (%_debug% eq 1) (%_64% eq 1)
Run Code Online (Sandbox Code Playgroud)
或者我必须声明不像变量那样:
SET _debug=1
SET _not_debug=0
SET _x64=1
SET _not_x64=0
Run Code Online (Sandbox Code Playgroud)
当我只有这两个变量时,这很容易,但我预计会有更多变量.
关于第6和第7行,我写道:
6 :: call again where %_debug% is now 0
7 :: call again where %_x64% is now 0
Run Code Online (Sandbox Code Playgroud)
我不感兴趣,实际上改变的价值观_debug和_x64为0.我想知道的是,如果有一种方法可以通过"不_var"的功能.这样我就可以保留参数的含义.
您可以最小化设置各种变量所需的代码:
for %%V in (debug x64) do set /a _%%V=1, _not_%%V=0
Run Code Online (Sandbox Code Playgroud)
仅仅使用四个值的两个标志来执行上述操作似乎很愚蠢.但随着你添加更多标志,它变得越来越有吸引力.
但我不明白为什么你不采取这一步 - 为什么不让你的例程期望有意义的文本参数而不是神秘的积分值.您的CALL不仅会被很好地记录下来,而且常规代码也会更容易理解.CALLer不再需要担心将有意义的文本转换为整数值.
如果你发现自己开发了带有可选参数的复杂例程,那么你应该看看/sf/answers/571380491/