2011-01-24 40 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