There is no need to use find
. You could try the following:
for file in /path/to/directory/**/*(.); do echo $file; done
or
for file in /path/to/directory/**/*(.); echo $file
- the
**
pattern matches multiple directories recursively. Soa/**/b
matches anyb
somewhere belowa
. It is essentially matches the listfind a -name b
produces. (.)
is a glob qualifier and tells zsh to only match plain files. It is the equivalent to the-type f
option fromfind
.- you do not really need double quotes around
$file
because zsh does not split variables into words on substitution. - the first version is the regular form of the
for
-loop; the second one is the short form withoutdo
anddone
The reason for the error you get is due to the last point: when running a single command in the loop you need either both do
and done
or none of them. If you want to run more than one command in the loop, you must use them.