Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: How to feed a command with the multiple results generated by one subcommand

Tags:

bash

gcc

I want to process each source code file after it has been preprocessed:

myprocess `gcc -E file1.c`  
myprocess `gcc -E file2.c`  
...  
myprocess `gcc -E fileN.c`  

This gets tedious so how do I make this a single command?
That is, something along the line:

myprocess SOMETHINGMAGIC(gcc -E file*.c)

Thanks in advance!

like image 440
John Lane Avatar asked Jan 23 '23 22:01

John Lane


2 Answers

You mean like

   for i in file*.c ; do
        myprocess `gcc -E $i`
    done
like image 125
Paul Tomblin Avatar answered Jan 26 '23 11:01

Paul Tomblin


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) $<
like image 37
dmckee --- ex-moderator kitten Avatar answered Jan 26 '23 12:01

dmckee --- ex-moderator kitten