在 Mac OS X 中运行多个不带参数的 shell 脚本

发布于 2024-11-01 22:56:35 字数 282 浏览 1 评论 0原文

我的目录中有许多脚本,全部以 deploy_ 开头(例如 deploy_example.com)。
我通常通过调用 ./deploy_example.com 一次运行它们。

我如何一个接一个地运行它们(或者如果可能的话一次运行......)?

我已经尝试过了:

find deploy_* | xargs | bash

但是失败了,因为如果这样调用它需要绝对路径。

I have many scripts in a directory that all start with deploy_ (for instance, deploy_example.com).
I usually run them one at a time by calling ./deploy_example.com.

How do I run them all, one after the other (or all at once if possible...)?

I've tried:

find deploy_* | xargs | bash

But that fails as it needs the absolute path if called like that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

橘寄 2024-11-08 22:56:35

您可以通过多种方式做到这一点。例如,您可以执行以下操作:

for i in deploy_* ; do bash $i ; done

You can do it in several ways. For example, you can do:

for i in deploy_* ; do bash $i ; done
复古式 2024-11-08 22:56:35

您可以简单地执行以下操作:

for x in deploy*; do bash ./$x; done

You can simply do:

for x in deploy*; do bash ./$x; done
疯到世界奔溃 2024-11-08 22:56:35

在子 shell 中执行,以防止当前的 IFS 和位置参数丢失。

( set -- ./deploy_*; IFS=';'; eval "$*" )

编辑:该序列被分解

(                     # start a subshell, a child process of your current shell

  set -- ./deploy_*   # set the positional parameters ($1,$2,...)
                      #   to hold your filenames

  IFS=';'             # set the Internal Field Separator

  echo "$*"           # "$*" (with the double quotes) forms a new string:
                      #   "$1c$2c$3c$4c..." 
                      #   joining the positional parameters with 'c',
                      #   the first character of $IFS

  eval "$*"           # this evaluates that string as a command, for example:
                      #    ./deploy_this;./deploy_that;./deploy_example.com
)

Performed in a subshell to prevent your current IFS and positional parameters from being lost.

( set -- ./deploy_*; IFS=';'; eval "$*" )

EDIT: That sequence broken down

(                     # start a subshell, a child process of your current shell

  set -- ./deploy_*   # set the positional parameters ($1,$2,...)
                      #   to hold your filenames

  IFS=';'             # set the Internal Field Separator

  echo "$*"           # "$*" (with the double quotes) forms a new string:
                      #   "$1c$2c$3c$4c..." 
                      #   joining the positional parameters with 'c',
                      #   the first character of $IFS

  eval "$*"           # this evaluates that string as a command, for example:
                      #    ./deploy_this;./deploy_that;./deploy_example.com
)
愛放△進行李 2024-11-08 22:56:35
find deploy_* | xargs -n 1 bash -c

将一一运行它们。查看xargs--max-procs 设置的手册页以获得一定程度的并行性。

find deploy_* | xargs -n 1 bash -c

Will run them all one after the other. Look at the man page for xargs and the --max-procs setting to get some degree of parallelism.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文