Makefile中的for循环不起作用 [英] For loop in makefile not working

查看:106
本文介绍了Makefile中的for循环不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Makefile中,我有:

In my makefile I have:

all:
  for i in {20..50000..10} ; do \
    echo "Computing $$i" ;\
  done

应该在单独的一行上分别打印数字20、30、40,...,50000.

Which should print numbers 20, 30, 40, ..., 50000 each on a separate line.

这在Debian oldstable(GNU Make 4.0,GNU Bash 4.3)下有效,但在Debian稳定版(GNU Make 4.1和GNU Bash 4.4.12)下无效.

This works under Debian oldstable (GNU Make 4.0, GNU Bash 4.3), but not Debian stable (GNU Make 4.1 and GNU Bash 4.4.12).

Debian稳定版仅打印字符串"{20..50000..10}".为什么是这样?在makefile文件中将此for循环编写的可移植方式是什么?

Debian stable prints just the string "{20..50000..10}". Why is this? What is the portable way to write this for loop in a makefile?

推荐答案

与POSIX兼容的循环粘在一起:

Stick with a POSIX-compatible loop:

all:
  i=20; while [ "$$i" -le 50000 ]; do \
    echo "Computing $$i"; i=$$((i + 10));\
  done

这篇关于Makefile中的for循环不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆