更新批处理文件中的命令行参数 [英] Updating a command line parameter in a batch file
本文介绍了更新批处理文件中的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在批处理文件中更新或替换命令行参数(如%1)?
Is it possible to update or replace a command line parameter (like %1) inside of a batch file?
示例代码:
rem test.cmd
@echo off
echo Before %1
IF "%1" == "123" (
set %%1 = "12345678"
)
echo After %1
所需结果:
C:/>Test 123
Before 123
After 12345678
实际结果:
C:/>Test 123
Before 123
After 123
推荐答案
否.您尝试的是不可能的.
No. What you are trying is not possible.
可以模拟将原始批处理参数传递给子例程,或使用修改后的参数递归调用同一cmd,这将再次获得%1,%2,...调用中提供的参数.但这不是你要的.
Can be simulated passing original batch parameters to subrutine, or call the same cmd recursively with modified parameters, which again get %1, %2, ... the parameters provided in the call. But this is not what you ask.
rem test.cmd
@echo off
echo Before %1
if "%~1"=="123" (
call :test %1234
) else (
call :test %1
)
goto :EOF
:test
echo After %1
这篇关于更新批处理文件中的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文