我想迭代一个文件列表.这个列表是find
命令的结果,所以我想出了:
getlist() {
for f in $(find . -iname "foo*")
do
echo "File found: $f"
# do something useful
done
}
Run Code Online (Sandbox Code Playgroud)
没关系,除非文件名中有空格:
$ 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
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能避免空格分裂?