开发者

Running multiple shell scripts without arguments in Mac OS X

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'开发者_JAVA百科ve tried:

find deploy_* | xargs | bash

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


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

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


You can simply do:

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


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
)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜