2014-03-06 75 views
1

工作,我有在for循環內貓命令。 for循環遍歷一堆文件夾。cat命令不是在一個循環

在我的代碼,我基本上都評論說出來,除了cat命令和外環。一旦我註釋掉循環,cat命令就可以工作。當我刪除cat命令以及其中的內容時,一切都正常。

我得到的錯誤是:語法錯誤:意外的文件結束。它總是指最後一行,就是在這種情況下完成的。

#!/bin/sh 
cd $HOME/filedirectory 
for k in *; do 
    cat > $HOME/mongodb/bin/script1.js << EOF 
     ##commented out stuff 
    EOF 
done 

回答

0

您需要在收盤前EOF刪除空間:

#!/bin/sh 
cd $HOME/filedirectory 
for k in *; do 
    cat > $HOME/mongodb/bin/script1.js << EOF 
     ##commented out stuff 
EOF 
done 

man bash

If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-docu- ments within shell scripts to be indented in a natural fashion.

所以,你可以在定界符運營商變更爲<<-。那麼您可以使用製表符縮進heredoc和分隔符。 (沒有空格