简体   繁体   English

如何将变量名称回显到批处理文件,以便目标文件可以使用该变量

[英]How to echo variable name to batch file so the destination file can use the variable

I am building a batch file. 我正在建立一个批处理文件。 I want the batch file to be generated, so I echo some lines to a batch file. 我希望生成批处理文件,因此我在批处理文件中回显了一些行。 The problem is the following: 问题如下:

I have generate.bat and backup.bat. 我有generate.bat和backup.bat。 When I start generate.bat, I gather some user info and save that to backup.bat. 当我开始generate.bat时,我收集了一些用户信息并将其保存到backup.bat。 In backup.bat I gather the date and the time. 在backup.bat中,我收集日期和时间。 I save that in a variable. 我将其保存在变量中。 How is it possible to save a variable name into that backup.bat, so it can be used in backup.bat 如何将变量名保存到该backup.bat中,以便可以在backup.bat中使用它

set /P ALOCATION=First loc.%=%
set /P BLOCATION=Second loc. %=%

echo robocopy "%ALOCATION%" "%BLOCATION%%thatpath%" /E /xd "%ALOCATION:~0,3%$Recycle.Bin" >> backup.bat

I already have some code in backup.bat: 我在backup.bat中已经有一些代码:

SET thatpath=%name%

After this set that I echo the robocopy mentioned above. 在此设置之后,我回显了上面提到的robocopy。 I, however, want it to use the "thatpath" every time the backup.bat is started. 但是,我希望每次启动backup.bat时都使用“ thatpath”。

So to be short: I have a generate.bat, I echo a line to backup.bat, and I would like the line to use a variable in backup.bat. 简而言之:我有一个generate.bat,我在backup.bat中回显了一行,并且我希望该行在backup.bat中使用一个变量。 I don't want it to be used in generate.bat, I just want it to be used when starting backup.bat 我不希望它在generate.bat中使用,我只是希望在启动backup.bat时使用它

You can solve this by using echo %%variable%% . 您可以使用echo %%variable%%解决此问题。 It then will be useful for the other batch file. 然后它将对其他批处理文件有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM