Bash: How to feed a command with the multiple results generated by one subcommand
If this is part of an ongoing processes (as opposed to a one time thing), use make
, it is good at automating work pipelines.
In particular use suffix rules with traditional make or gmake style implicit rules.
Here is an outline for a suffix rule implementation:
.c.cpre: $(CC) -E $(CPPFLAGS) -o $@ $<.cpre.cmy: $(MY_PROCESS) $< # Or whatever syntax you support.. # # You could # $(RM) $< # here, but I don't recommend it.cmy.o: $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< # $(RM) $<
No magic nedded, just
my_process $(gcc -E *.c)
Note that I used the $(command) form because backticks are deprecated.
As an aside: are you sure you want to do that? You are putting the whole output of gcc -E as command line parameters of my_process. Not sure this is what you want. Maybe you want to use a simple pipe
gcc -E file.c | my_process
so that the output of gcc becomes the input of my_process.
In the latter case something like
for c_file in *.c ; do gcc -E $c_file | myprocess > ${c_file}.processeddone
would do the trick.