In my makefile I have:
all:
for i in {20..50000..10} ; do \
echo "Computing $$i" ;\
done
Which should print numbers 20, 30, 40, ..., 50000 each on a separate line.
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 stable prints just the string "{20..50000..10}". Why is this? What is the portable way to write this for loop in a makefile?
If you run this at your shell prompt:
/bin/sh -c 'for i in {20..5000..10}; do echo $i; done'
you'll see it doesn't work as you'd hoped. Make always invokes /bin/sh (which should be a POSIX shell) to run recipes: it would be a disaster for portability if it used whatever shell the person invoking the makefile happened to be using.
If you really want to write your makefile recipes in bash syntax, then you have to ask for that explicitly by adding:
SHELL := /bin/bash
to your makefile.
Stick with a POSIX-compatible loop:
all:
i=20; while [ "$$i" -le 50000 ]; do \
echo "Computing $$i"; i=$$((i + 10));\
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With