Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute each command in a list?

Tags:

makefile

If I have a list of n commands, c = c1 ... cn, how can I execute them in order for a given target? I tried the foreach construct

$(foreach x,$(c),./$(x))

but that puts all the commands on one line. Any clues?

like image 554
August Karlstrom Avatar asked Sep 21 '12 10:09

August Karlstrom


People also ask

How do I execute a Linux command list?

First, put a { on its own line. Then, insert your commands. Then, put a } on a new line and press Enter . Your commands will be executed.

How do I run a script in all files in a directory?

We can run all scripts in a directory or path using "run-parts" command. The run-parts command is used to run scripts or programs in a directory or path.


1 Answers

You identified the problem (“but that puts all the commands on one line”). You just need to append a newline whenever you expand $x in your loop.

define \n


endef

Now simply use $(foreach x,$c,./$(x)${\n}) in your recipe.

like image 89
bobbogo Avatar answered Oct 04 '22 15:10

bobbogo