chrism01's link is for reading text from a file and operating on the contents. That's not what the OP asked for.
And Keith's is really just a variation of the same technique, only it uses the input from find
as the text source, and runs the commands on that list. It will probably work, unless the filenames themselves actually contain newlines, but I see nothing there that simple globbing
can't handle already (and I would simply use find
option instead of the loop anyway).
In fact, the OP's code should work just fine as it stands, as far as I can tell, and indeed I would've given pretty much that exact solution. The variable contains a globbing pattern which would expand when the for
loop is executed, which it should be able to read correctly and run the sub-commands on.
The only way I can see it failing is if the "$f
" variable were not quoted in the subcommands (which would allow word-breaking on the contents), or if "$FILES
" was quoted in the outside loop (in which case the content would be seen as a single entry, an unexpanded glob). But the loop as posted doesn't show either of those errors.
If the posted loop is indeed the exact command that was run, then the OP needs to explain in exactly what way it's not working. What errors or output are you actually getting?