如何串联批处理文件的命令行参数? [英] How to concatenate command line args for a batch file?
问题描述
我目前正在尝试将命令行参数与此连接起来:
I'm currently attempting to concatenate my command line arguments with this:
for %%a in (%*) do set "subject=%subject% %%a"
例如,如果我跑步
my.bat subject line here
应该将我的主题变量设置为此处的主题行",并保留空格.但是,当前运行之后,我的subject变量设置为最后一个单词.我得到的主题值为这里".
it should set my subject variable to "subject line here", preserving the spaces. However, currently after the run, my subject variable is set to the last word. I get a subject value of " here."
如何正确连接命令行参数?
How to concatenate the command line arguments right?
推荐答案
您不能这样做:
SET subject=%*
或者启用延迟扩展,以便在解析过程中不会替换环境变量.
Alternatively enable delayed expansion so that the environment variables don't get substituted during parsing.
Setlocal EnableDelayedExpansion
for %%a in (%*) do set subject=!subject! %%a
echo %subject%
请参见>%variable%与!variable之间的差异!批处理文件中以获取更多信息.
see Difference between %variable% and !variable! in batch file for more info.
这篇关于如何串联批处理文件的命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!