【发布时间】:2018-05-02 22:48:37
【问题描述】:
在我的 makefile 中有:
all:
for i in {20..50000..10} ; do \
echo "Computing $$i" ;\
done
应该在单独的行上分别打印数字 20、30、40、...、50000。
这适用于 Debian oldstable(GNU Make 4.0、GNU Bash 4.3),但不适用于 Debian stable(GNU Make 4.1 和 GNU Bash 4.4.12)。
Debian stable 只打印字符串“{20..50000..10}”。为什么是这样?在 makefile 中编写这个 for 循环的可移植方式是什么?
【问题讨论】:
-
对我来说,在我将
$$i替换为$i后,它起作用了。你能试试吗? -
@dmadic 这对我不起作用。我的软件什么都不打印(它可能将
$i视为makefile 变量并打印空字符串)。 -
你为什么不用
seq?seq 20 10 50000 -
seq并不比大括号更标准,因此它增加了一个并非绝对必要的外部依赖项。 -
大括号是一种 bashism,因此您应该安装 bash - 另一个外部依赖项 :) 参见 MadScientist 的回答 (stackoverflow.com/a/50144927/934599)