我想遍历文件列表。这个列表是 find
命令的结果,所以我想出了:
getlist() {
for f in $(find . -iname "foo*")
do
echo "File found: $f"
# do something useful
done
}
没关系,除非文件的名称中有空格:
$ ls
foo_bar_baz.txt
foo bar baz.txt
$ getlist
File found: foo_bar_baz.txt
File found: foo
File found: bar
File found: baz.txt
我能做些什么来避免空间分割?
原文由 gregseth 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以将基于单词的迭代替换为基于行的迭代: