如何在 Windows 中的批处理脚本中正确执行 FOR 循环

如何在 Windows 中的批处理脚本中正确执行 FOR 循环

我正在尝试从 bash 脚本进行转换,这就是我想到的。
当我尝试运行它时,我收到the syntax of the command is incorrect错误。我跟着这个帖子并写下了命令。这个批处理脚本有什么问题?

REM This scripts downloads the mnist data and unzips it.
SET wget="../../tools/3rdparty/bin/wget.exe"
SET gunzip="../../tools/3rdparty/bin/gunzip.bat"

ECHO "Downloading..."

FOR %%G IN (train-images-idx3-ubyte train-labels-idx1-ubyte t10k-images-idx3-ubyte t10k-labels-idx1-ubyte)
DO
    %wget% --no-check-certificate http://yann.lecun.com/exdb/mnist/%%G.gz
    %gunzip% %%G.gz

ECHO "Done."

答案1

REM This scripts downloads the mnist data and unzips it.
SET wget="../../tools/3rdparty/bin/wget.exe"
SET gunzip="../../tools/3rdparty/bin/gunzip.bat"

ECHO "Downloading..."

FOR %%G IN (train-images-idx3-ubyte train-labels-idx1-ubyte t10k-images-idx3-ubyte t10k-labels-idx1-ubyte) DO (
    %wget% --no-check-certificate http://yann.lecun.com/exdb/mnist/%%G.gz
    %gunzip% %%G.gz
)
ECHO "Done."

如果在 for 循环中使用许多命令,则需要用 () 括号括起来。

相关内容