2015-06-20 106 views
1

我試圖循環通過生成文件在特定目錄中的.c文件。嵌套For循環在生成文件

我用下面的代碼,但它似乎不工作:

DIR= Sources \ 
    Sources_2 

@for entry in ${DIR} ;     \ 
do           \ 
    @for i in $${entry}/*.c ;    \ 
    do          \ 
     echo "Processing $${i}";    \ 
     #Building Commands go here 
    done         \ 
done 

我得到錯誤: 「/ bin/sh的:-c:3行:語法錯誤附近意外的標記'做'」

回答

0

你不應該靠近第二for循環at符號@使用。應該在整個shell命令的開頭使用@。以下爲我工作:

DIR= Sources \ 
    Sources_2 

all: 
    @for entry in ${DIR};     \ 
    do          \ 
     for i in $${entry}/*.c;    \ 
     do         \ 
      echo "Processing $${i}";  \ 
     done        \ 
    done 
+0

生成錯誤:***缺少分隔符。停止。 –

+0

@ user3438074這是Makefile本身的一些錯誤,而不是在shell腳本中。我已經測試了上面的代碼,它完全有效。 –

+0

好的,謝謝Oleg,我會看看Makefile中有什麼問題...非常感謝您的幫助 –

1

更改Makefile如下

@for entry in ${DIR} ; do   \ 
    for i in $$entry/*.c ; do  \ 
     echo "Processing $$i";  \ 
     #Building Commands go here 
    done        \ 
done 

的原因是for循環的錯誤的語法用法。

+0

檢查更新的答案。刪除'entry'的大括號 –

+0

生成錯誤:***缺少分隔符。停止 –

+0

顯示您正在使用的整個'Makefile' –