我发现自己经常做以下事情:
for f in `find -foo -bar -baz`; do
process "$f"
done
这当然不适用于带空格的文件名。我该如何处理这种情况?
最佳答案
Find 和 xargs 可以很好地协同工作。 find 可以使用 \0
分隔符(选项 print0
)打印文件名,xargs 可以以该格式(选项 -0
)读取它们>):
find . -type f -print0 | xargs -0 echo
关于bash - 如何对名称中包含空格的文件执行 shell "for"命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2272837/