On 14 March 2016 at 13:32, Martin Reinders <mar...@helios.de> wrote: > Hello, > > I am experiencing unexpected results if both the $(file ...) function > (that was introduced with GNU make version 4) and other command-line > utilities are used to produce a single file. > > Here is a minimal example. (The "echo" command is used for demonstration > purposes, it stands for any external command-line utility writing to > standard output.) > > $ cat Makefile > all: > /bin/echo "LINE FROM ECHO COMMAND" > file.txt > $(file >>file.txt,LINE FROM FILE FUNCTION) > > $ make > /bin/echo "LINE FROM ECHO COMMAND" > file.txt > > $ cat file.txt > LINE FROM ECHO COMMAND > > I expected that the echo command writes one line to the file, and the > $(file ...) function appends another line. But as one can see, the file > contains the output from the echo command only. It seems to me that the > echo command is executed _after_ executing the $(file ...) function. >
Functions and variables are expanded before the command and list of variables is sent to the shell to be executed. Hence $(file) happens before your echo command is executed. Why would you use $(file) in a commandline anyhow? The usefulness of $(file) is as a way, for example, to get around commandline length limits e.g. when listing hundreds of files to put in a zip or to create configuration files for a build in a platform independent way or things of that nature. It's not really there to replace bash commands. Regards, Tim _______________________________________________ Help-make mailing list Help-make@gnu.org https://lists.gnu.org/mailman/listinfo/help-make