有没有一种方法可以将long并重复执行“ set”命令缩减为一个命令?

时间:2019-11-04 13:19:32

标签: batch-file cmd

所以我得到了下面的代码,它将变量设置为另一个变量

  set c1_page_%page_num%=%c1% 
  set c2_page_%page_num%=%c2% 
  set c3_page_%page_num%=%c3% 
  set c4_page_%page_num%=%c4% 
  set c5_page_%page_num%=%c5% 
  set c6_page_%page_num%=%c6% 
  set c7_page_%page_num%=%c7% 
  set c8_page_%page_num%=%c8% 
  set c9_page_%page_num%=%c9% 
  set c10_page_%page_num%=%c10%
  set c11_page_%page_num%=%c11%
  set c12_page_%page_num%=%c12%
  set c13_page_%page_num%=%c13%
  set c14_page_%page_num%=%c14%
  set c15_page_%page_num%=%c15%

我仍然需要以某种方式仍然能够仅用一行代码或更多行代码将所有变量设置为另一个变量。请帮助我

1 个答案:

答案 0 :(得分:3)

我假设您想要一行可以为您完成工作?

@echo off
for /l %%i in (1,1,15) do call set c%%i_page_%page_num%=%%c%%i%%

或使用delayedexpansion

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,15) do set c%%i_page_%page_num%=!c%%i!