In a Makefile, I need to cycle through a list and write the current element of the list in a file. The code is the following:
SHELL := /bin/bash
LIST = A B C
for i in $(LIST) do \
echo $ii > file.txt \
I get the following error:
/bin/bash: -c: line 1: syntax error near unexpected token `>'
Do you know how to fix it?
Best How To :
You are missing a ; after
$(LIST). You need to terminate the list of words you are giving to
for before you can start the
As indicated in the comments, you additionally need a : at the end of the
echo line (the command that gets run has no newlines the way this works at the normal command line so you need to explicitly separate the commands from each other).
And further, to get the results you expect, you need to escape the $ in the shell command by using
$$i (also pick one of
$ii as your variable name).