1) To start with, let's get the proper syntax for find
find <start_dirs> <global_opts> <matching_opts> <actions>
You need to have one or more starting directories, at the least. The default action is -print
, so you don't really need to include it, but it never hurts to be complete.
2) The output of find
is likely to be a list
of files, not just one, so you really need run a shell loop on the output. And since filenames can include spaces, you need to be able to handle them safely. This means you need to use -print0 null separators
How can I find and deal with file names containing newlines, spaces or both?
3) You need to split the string itself into individual elements. While this can be done with something like sed
, it's really easier to just use read
with the appropriate IFS setting and output to an array (unless you can guarantee the number of levels you'll get, in which case you can use individual variables).
Since you'll already be using it in the while
loop mentioned above, this is the recommended option.
And see here for more on what you can do with shell built-ins:
How do I do string manipulations in bash?