I want to execute these commands
./a.out 1
./a.out 2
./a.out 3
./a.out 4
.
.
.so on How to write this thing as a loop in make file?
I want to execute these commands
./a.out 1
./a.out 2
./a.out 3
./a.out 4
.
.
.so on How to write this thing as a loop in make file?
The following will do it, if (as I assume by your use of ./a.out
) you're on a UNIXy platform.
for number in 1 2 3 4 ; do \
./a.out $$number ; \
done
Test as follows:
qwert:
for number in 1 2 3 4 ; do \
echo $$number ; \
done
produces:
1
2
3
4
For bigger ranges, use:
qwert:
number=1 ; while [[ $$number -le 10 ]] ; do \
echo $$number ; \
((number = number + 1)) ; \
done
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.
Nested loops can be done thus:
qwert:
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
producing:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
4 1
4 2
4 3
If you're using GNU make, you could try
NUMBERS = 1 2 3 4 doit: $(foreach var,$(NUMBERS),./a.out $(var);)
which will generate and execute
./a.out 1; ./a.out 2; ./a.out 3; ./a.out 4;