https://stackoverflow.com/questions/10121182/multiline-bash-commands-in-makefile
test:
ports=(8090 8091 8092 8093); \
for p in $${ports[@]}; \
do \
curl localhost:$$p; \
echo ""; \
done;
# make test
ports=(8090 8091 8092 8093); \
for p in ${ports[@]}; \
do \
curl localhost:$p; \
echo ""; \
done;
hello world port 9000 sleep 1
hello world port 9001 sleep 2
hello world port 9000 sleep 1
hello world from monitor
foo:
for i in `find`; \
do \
all="$$all $$i"; \
done; \
gcc $$all
- Escape the script’s use of $ by replacing with $$
- Convert the script to work as a single line by inserting ; between commands
- If you want to write the script on multiple lines, escape end-of-line with \
- Optionally start with set -e to match make’s provision to abort on sub-command failure
- This is totally optional, but you could bracket the script with () or {} to emphasize the cohesiveness of a multiple line sequence – that this is not a typical makefile command sequence Here’s an example inspired by the OP:
mytarget:
{ \
set -e ;\
msg="header:" ;\
for i in $$(seq 1 3) ; do msg="$$msg pre_$${i}_post" ; done ;\
msg="$$msg :footer" ;\
echo msg=$$msg ;\
}