shell - 如何在 Unix 中同时搜索并执行两个脚本?

标签 shell unix sh aix

假设您有一个包含两个文件的文件夹。

示例:stop_tomcat_center.shstart_tomcat_center.sh

在我的示例中,ls *tomcat* 返回这两个脚本。 如何同时搜索并执行这两个脚本?

我试过了

ls *tomcat* | xargs sh

但只执行第一个脚本(不执行第二个)。

最佳答案

并行执行多项操作的简单方法是使用 GNU Parallel:

parallel ::: ./*tomcat*

或者,如果您的脚本第一行没有 shebang:

parallel bash ::: ./*tomcat*

或者如果您喜欢xargs:

ls *tomcat* | xargs -P 2

关于shell - 如何在 Unix 中同时搜索并执行两个脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52406113/

相关文章:

regex - sed:替换包含模式的行

sockets - "sin"在 sin_addr、sin_family 等中是什么意思?

linux -/系统/bin/sh : cat:duty_pcts:I/O error

linux - 使用 sh 运行 bash 脚本

linux - 如何在删除前检查文件是否存在?

python - 如何在 Wing IDE 中终止 Python shell?

linux - Linux内核如何处理隐藏文件?

mysql - 如何使用其他文件中的凭据以及如何在 crons 中传递 dir 位置?

shell - 运行带有算术运算的脚本时获取 "numeric argument required"

c - Shell 程序中的 fork() 和 wait()