2009-01-15 36 views
4

我要處理每一個源代碼文件中的命令後已預處理:擊:如何養活由一個子產生的多個結果

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

這變得乏味讓我怎麼做這單命令?
也就是說,沿線的東西:

myprocess SOMETHINGMAGIC(gcc -E file*.c) 

提前感謝!

回答

5

你的意思是像

for i in file*.c ; do 
     myprocess `gcc -E $i` 
    done 
+0

我認爲你的意思是「for」不是「foreach」的bash。 – 2009-01-15 15:59:45

+0

是的,它應該是: 我在文件* .c中;做 – skinp 2009-01-15 16:03:54

2

如果這是一個正在進行的過程的一部分(而不是一次性的東西),使用make,這是件好事,在自動化工作管線。

特別是使用傳統make或gmake風格隱式規則的後綴規則。

這裏是一個後綴規則實施大綱:

.c.cpre: 
     $(CC) -E $(CPPFLAGS) -o [email protected] $< 
.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 [email protected] $< 
     # $(RM) $< 
1

也許這是你在找什麼?:

for i in file*.c ; do 
    echo "Header for myprocess: $i" 
    gcc -E $i 2>&1 
done | myprocess 

2>&1假設你想抓住標準錯誤,也
echo ...給我myprocess每個彙編的起點

0

如何:

myprocess {$(gcc -E file1.c),$(gcc -E file2.c),$(gcc -E file3.c)} 

或者,如果你管吧:

{$(gcc -E file1.c),$(gcc -E file2.c),$(gcc -E file3.c)} | myprocess 

它已經有一段時間,因爲我用的bash,所以,請指出我的錯誤!

1

沒有魔法nedded,只是

my_process $(gcc -E *.c) 

請注意,我用了$(命令)的形式,因爲反引號已被棄用。

撇開:你確定要做?您將gcc -E的整個輸出作爲my_process的命令行參數。不知道這是你想要的。也許你想用一個簡單的管道

gcc -E file.c | my_process 

這樣gcc的輸出成爲my_process的輸入。

在後一種情況下,像

for c_file in *.c ; do 
    gcc -E $c_file | myprocess > ${c_file}.processed 
done 

會做的伎倆。

0

ls file * .c | xargs --replace myprocess $(gcc -E {})

相關問題