无法在Windows批处理循环中设置变量

时间:2018-02-19 15:14:15

标签: batch-file for-loop

在逐行读取文件的for循环中,我想将输入参数存储在变量中。在下面的例子中,我重现了这个问题。我尝试将 %% a 存储到变量文本,但该变量仍为空。

如果我们假设文件 OneLiners.txt 包含两行文字

You won't drink away the alcoholism.
A liberal is just a conservative that hasn't been mugged yet.

并运行这样的脚本

@echo off
for /f "tokens=*" %%a in (OneLiners.txt) do (
  set text=%%a

  echo %%a 
  echo %text%
)

将回显

You won't drink away the alcoholism.
ECHO is off. 
A liberal is just a conservative that hasn't been mugged yet.   
ECHO is off.

表示变量为空。 如何将参数的内容分配给变量?我认为这是做到这一点的方法。

0 个答案:

没有答案