Here's what I have so far:
for file in $(find /path/to/directory -type f); echo $file; done
but I get this error:
zsh: parse error near `done'
Here's what I have so far:
for file in $(find /path/to/directory -type f); echo $file; done
but I get this error:
zsh: parse error near `done'
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
**
pattern matches multiple directories recursively. So a/**/b
matches any b
somewhere below a
. It is essentially matches the list find 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 from find
.$file
because zsh does not split variables into words on substitution.for
-loop; the second one is the short form without do
and done
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.
Can you check if adding ""
around $file
solves this problem like so:
for file in $(find /path/to/directory -type f); echo "$file"; done
Edit:
add do
before echo
and let me know if it solves the problem:
for file in $(find /path/to/directory -type f); do echo "$file"; done