这应该为你做 -
使用find -type d
选项,您将查找搜索限制为目录。提供一个pattern with -not -name
可以帮助您忽略匹配的目录。-exec option
可以帮助您启动已找到的所有目录的 shell 脚本。{} \;
只是意味着 exec 为每个目录一次执行一个 shell 脚本的缓冲区空间。-depth n
将确保它下降到 n 个目录级别。
find . -not -name ref\* -not -name .\* -type d -depth 1 -exec ./script.sh {} \;
更新:
我的错,我忘了处理两个用户驱动的参数。我可能不是专家,但我想到的最简单的方法是将查找结果发送到文件,然后在该文件上运行 for 循环。
像这样的东西-
[jaypal~/Temp]$ find . -not -name ref\* -not -name .\* -type d -depth 1 > dirlist
[jaypal~/Temp]$ for i in dirlist; do ./script.sh $i param1 param2; done
传递用户驱动参数的替代方法(如@dma_k 所建议)
[jaypal~/Temp]$ find . -not -name ref\* -not -name .\* -type d -depth 1 | xargs script.sh param1 param2