2011-01-24 49 views
2

我寫了一個shell腳本,它在所有目錄內遞歸地選取所有文件,並準備一個報告,其中包含上次修改的文件大小。 我面臨的問題是,很少有名稱爲「用戶界面」的文件(介於兩者之間的空間)。如何在shell腳本的for循環中使用那些文件並獲取其中的文件和目錄。 在此先感謝文件名與空間

+3

你能告訴我們,您對腳本一直在使用。 – codaddict 2011-01-24 11:09:39

回答

3

只要把雙引號"$FILENAME"

2

你可能會嘗試使用類似for file in $(command)之間的文件名可變。相反,使用通配符while read循環或for循環。確保你引用了包含filenamess的變量。

#!/bin/sh 
command | while read -r file 
do 
    something_with "$file" 
done 

,或者在支持進程替換彈:

#!/bin/bash 
while read -r file 
do 
    something_with "$file" 
done < <(command) 

如果你只是遍歷文件列表:

for file in "$dir"/* 
do 
    something_with "$file" 
done