PDA

View Full Version : Inserting text in for loop variable of makefile.



himanshu18july
September 9th, 2009, 03:24 PM
Hi All,

I'm facing a problem with the for loop variable of makefile.

I want to insert some text at the end of each variable in a list.
For example, I have a list as "first second third" and I want to insert "_july" in all the variables of the list so that list becomes "first_july second_july third_july" and print it in some file.
Now the code I'm using for this is



LIST = first second third
for i in $(LIST); do \
echo "$$i_july" >> test.txt; \
done


But this piece of code is not working.

Can you people please suggest me the modification required.

Thanks in advance.

korin43
September 11th, 2009, 11:22 PM
You're putting the variable in in a sort of insane way. I'm not sure of the syntax of makefiles, but just add the two variables together:

LIST = first second third
for i in $(LIST); do \
echo "$i$_july" >> test.txt; \
done
or

LIST = first second third
for i in $(LIST); do \
echo $i + $_july >> test.txt; \
done
or if that doesn't work


LIST = first second third
for i in $(LIST); do \
echo $i >> test.txt \
echo $_july >> test.txt; \
done