I am writing a script to create a Makefile. I used a for-loop to iterate through all my arguments to 'echo ... >> Makefile' into the command section of each target. The expected output goes something like this:
$ makemake.sh a.out -Hello -World $ cat Makefile > a.out : appointment.o calendar.o day.o dayofweek.o time.o year.o > g++ -ansi -Wall -g -o a.out -Hello -World
However, using the technique above:
echo -n "g++ -ansi -Wall -g -o " >> Makefile for arg in $@; do echo -n "$@ " >> Makefile done
Yields the following:
a.out : appointment.o calendar.o day.o dayofweek.o time.o year.o g++ -ansi -Wall -g -o a.out -Hello -World a.out -Hello -World a.out -Hello -World
My professor recommended I use shift, but this would make it more difficult to recall arguments for other targets.
Why is this happening and what can I do? Though I still seek an answer, I am very interested in the logic behind this reaction.