Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file Bat文件上全局变量内的参数解析_Batch File - Fatal编程技术网

Batch file Bat文件上全局变量内的参数解析

Batch file Bat文件上全局变量内的参数解析,batch-file,Batch File,可以从变量内部使用参数吗 我需要有一个全局变量,它将在一些bat文件的开头使用 设置变量 setx var "echo %~n0 %*" 蝙蝠样本 %var% > lastBatExecuted.txt set /p last=<lastBatExecuted.txt if "%last%"=="%~n0 %*" echo it worked pause %var%>lastBatExecuted.txt set/p last=是,此方法有效,但您需要使用双百分号定义变量值,并插

可以从变量内部使用参数吗

我需要有一个全局变量,它将在一些bat文件的开头使用

设置变量

setx var "echo %~n0 %*"
蝙蝠样本

%var% > lastBatExecuted.txt
set /p last=<lastBatExecuted.txt
if "%last%"=="%~n0 %*" echo it worked
pause
%var%>lastBatExecuted.txt

set/p last=是,此方法有效,但您需要使用双百分号定义变量值,并插入额外的
调用
命令,以便在第一次
%var%
展开后重新计算百分号。请参阅此测试:

@echo off
setlocal

set "var=echo One: %%~n0 %%*"
%var%
call %var%

set "var=call echo Two: %%~n0 %%*"
%var%
用法示例:

C:\> test Arg1 Arg2
输出

One: %~n0 %*
One: test Arg1 Arg2
Two: test Arg1 Arg2
当通过
setx
命令定义
var
时,同样的行为也应该起作用