如何在 Makefile 中编写循环? [英] How to write loop in a Makefile?
本文介绍了如何在 Makefile 中编写循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想执行以下命令:
./a.out 1
./a.out 2
./a.out 3
./a.out 4
.
.
. and so on
如何在Makefile
中将这个东西写成一个循环?
How to write this thing as a loop in a Makefile
?
推荐答案
如果,正如我假设您使用 ./a.out
,您在 UNIX 上,以下将执行此操作-类型平台.
The following will do it if, as I assume by your use of ./a.out
, you're on a UNIX-type platform.
for number in 1 2 3 4 ; do
./a.out $$number ;
done
测试如下:
target:
for number in 1 2 3 4 ; do
echo $$number ;
done
产生:
1
2
3
4
对于更大的范围,请使用:
For bigger ranges, use:
target:
number=1 ; while [[ $$number -le 10 ]] ; do
echo $$number ;
((number = number + 1)) ;
done
这会输出 1 到 10(包括 1 到 10),只需将 while
终止条件从 10 更改为 1000,以获得更大的范围,如您的评论所示.
This outputs 1 through 10 inclusive, just change the while
terminating condition from 10 to 1000 for a much larger range as indicated in your comment.
嵌套循环可以这样完成:
target:
num1=1 ; while [[ $$num1 -le 4 ]] ; do
num2=1 ; while [[ $$num2 -le 3 ]] ; do
echo $$num1 $$num2 ;
((num2 = num2 + 1)) ;
done ;
((num1 = num1 + 1)) ;
done
制作:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
4 1
4 2
4 3
这篇关于如何在 Makefile 中编写循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文