I want to iterate over a list of files. This list is the result of a find
command, so I came up with:
getlist() {
for f in $(find . -iname \"f
find
has an -exec
argument that loops over the find results and executes an arbitrary command. For example:
find . -iname "foo*" -exec echo "File found: {}" \;
Here {}
represents the found files, and wrapping it in ""
allows for the resultant shell command to deal with spaces in the file name.
In many cases you can replace that last \;
(which starts a new command) with a \+
, which will put multiple files in the one command (not necessarily all of them at once though, see man find
for more details).