How do I apply a shell command to many files in nested (and poorly escaped) subdirectories?

后端 未结 6 1621
别跟我提以往
别跟我提以往 2020-12-06 03:31

I\'m trying to do something like the following:

for file in `find . *.foo`
do
somecommand $file
done

But the command isn\'t working because

6条回答
  •  庸人自扰
    2020-12-06 03:46

    Instead of relying on the shell to do that work, rely on find to do it:

    find . -name "*.foo" -exec somecommand "{}" \;
    

    Then the file name will be properly escaped, and never interpreted by the shell.

提交回复
热议问题