简体   繁体   中英

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'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

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

for x in deploy*; do bash ./$x; done
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.

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
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM