这个问题的灵感来自
我看到这些结构
for file in `find . -type f -name ...`; do smth with ${file}; done
Run Code Online (Sandbox Code Playgroud)
和
for dir in $(find . -type d -name ...); do smth with ${dir}; done
Run Code Online (Sandbox Code Playgroud)
几乎每天都在这里使用,即使有些人花时间对这些帖子发表评论,解释为什么应该避免这种东西......
看到此类帖子的数量(以及有时这些评论被简单地忽略的事实)我想我还不如问一个问题:
为什么循环find
的输出是不好的做法,为 返回的每个文件名/路径运行一个或多个命令的正确方法是find
什么?
我写了一个正则表达式,它在某个程序(grep、sed、awk、perl、python、ruby、ksh、bash、zsh、find、emacs、vi、vim、gedit 等)中运行良好。但是当我在不同的程序(或不同的 unix 变体)中使用它时,它会停止匹配。为什么?