[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What is the difference between > and >> in a makefile.
From: |
givemecode |
Subject: |
Re: What is the difference between > and >> in a makefile. |
Date: |
Mon, 28 Mar 2011 12:55:32 -0700 (PDT) |
Paul Smith-20 wrote:
>
> On Mon, 2011-03-28 at 11:15 -0700, givemecode wrote:
>> I modified a for loop in a makefile that looked like this:
>>
>> @for f in $(DRV_GEN_HEADER) ; do echo "#include \""$$f"\"" >> $@ ; done
>>
>> which puts the output of echo into a new file I sepcified.
>>
>> changed to this:
>>
>> @for f in $(INCLUDE_DIR)/%.h); do \
>> echo "#include \""$$f"\""; \
>> done > '$@'
>>
>> which does the same thing but the writing is done after the loop
>> completes
>> (I think). Can someone please explain the difference and why it works?
>
> This is a question about shell programming, not about makefiles and is
> probably better asked in help list for shell hacking.
>
> However, I can answer it for you :-)
>
> Note that the latter does NOT do all the writing after the loop
> completes. The file is written to, one line at a time, just as in the
> first example.
>
> The first example says for each file, echo this one line and append it
> (hence ">>" which is append) to the file address@hidden
>
> The second example says, for each file echo this one line, and redirect
> all output from all commands run inside the for-loop to overwrite the
> file $@ (hence ">" which is overwrite--i.e., truncate and write from
> scratch).
>
> Some differences between the two:
>
> 1. If the file $@ exists before the command is invoked, then the
> first version will append the new content to the
> already-existing content... this is probably not what you want
> in this situation. The second version will always recreate the
> file from scratch.
> 2. If you wanted to print some content to stdout and some to the
> file, then you have to use the first version because the second
> version will put all stdout from all commands in the for loop
> into the file (well, you can play fancy tricks with file
> descriptors but it's hardly worth it).
>
>
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-make
>
>
thanks to both of you. so the second version doesn't only write after the
for loop is complete? i guess that's just how i am reading it since it is
after the "done" keyword. what about this line tells the redirect to only
print the one line above it: "done > '$@'" ?
--
View this message in context:
http://old.nabble.com/What-is-the-difference-between-%3E-and-%3E%3E-in-a-makefile.-tp31260849p31261662.html
Sent from the Gnu - Make - Help mailing list archive at Nabble.com.
Re: What is the difference between > and >> in a makefile., givemecode, 2011/03/28