Windows 上的 Makefile For 循环

发布于 2024-08-17 09:10:35 字数 874 浏览 2 评论 0原文

这是一个与我在这里询问。我运行的是Windows XP。

我正在尝试让 for 循环在 Windows 上工作。按照的建议我必须确保该命令是有效的cmd命令,我构建了一个有效的for循环批处理命令:

@echo off
FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
DO ^
echo Date paid %%G ^ 

并将其放入Makefile中。这是 makefile 的内容:

all:
    @echo off
    FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
    DO ^
    echo Date paid %%G ^

但是,我仍然收到错误:

FOR /F "tokens=4 delims=," %%G IN ("存款,500,123.4,12-AUG-09") ^ make: *** [全部] 错误 255

知道如何解决这个问题吗?

This is a similar question to the one I ask here. I am running on Windows XP.

I am trying to get for loop to work on Windows. Following the suggestion that I have to make sure that the command are valid cmd command, I constructed a valid for loop batch command:

@echo off
FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
DO ^
echo Date paid %%G ^ 

And put it in a Makefile. This is the content of the makefile:

all:
    @echo off
    FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
    DO ^
    echo Date paid %%G ^

But still, I got an error:

FOR /F "tokens=4 delims=," %%G IN
("deposit,500,123.4,12-AUG-09") ^
make: *** [all] Error 255

Any idea how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

各空 2024-08-24 09:10:35

我找到了答案,这是在 Makefile Windows 中运行的正确语法:

all:
    @echo off
    FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") \
    DO   \
    echo Date paid %%G echo 123

I've found the answer, this is the correct syntax that runs in Makefile Windows:

all:
    @echo off
    FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") \
    DO   \
    echo Date paid %%G echo 123
甩你一脸翔 2024-08-24 09:10:35

我发现通过使用 &&您可以在 for 循环内执行多个命令,如下所示:

    for %%i in ($(SOMETHING)) do echo %%i 1 && echo %%i 2 && echo %%i 3

这将打印出如下内容:

1 1
2 2
3 3

I've found that by using && you can do multiple commands inside the for loop like so:

    for %%i in ($(SOMETHING)) do echo %%i 1 && echo %%i 2 && echo %%i 3

This will printout something like:

1 1
2 2
3 3
扎心 2024-08-24 09:10:35

你的分割是错误的,不要使用^。执行如下操作:

@echo off
FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") DO  (
    echo Date paid %%G
    rem you can put as many lines as you want here, inside of braces
    echo 123
)

your split is wrong, don't use ^. Do as following:

@echo off
FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") DO  (
    echo Date paid %%G
    rem you can put as many lines as you want here, inside of braces
    echo 123
)
关于从前 2024-08-24 09:10:35

也许您可以从 Makefile 调用批处理命令文件?

all:
    MyBatch.bat "deposit,$4500,123.4,12-AUG-09"

用MyBatch.bat如下。

@echo off
FOR /F "tokens=4 delims=," %%G IN ("%1") ^
DO ^
echo Date paid %%G ^

注意 Makefile 中的 $ 思想。 $ 是转义字符,必须加倍才能在字符串中得到一个真正的 $。

Maybe you can call your batch command file from the Makefile?

all:
    MyBatch.bat "deposit,$4500,123.4,12-AUG-09"

With MyBatch.bat as follows.

@echo off
FOR /F "tokens=4 delims=," %%G IN ("%1") ^
DO ^
echo Date paid %%G ^

Beware the $ in the Makefile thought. $ is the escape characher and have to be doubled to get one real $ in strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文