簡體   English   中英

在Mac OS X中運行多個不帶參數的Shell腳本

[英]Running multiple shell scripts without arguments in Mac OS X

我的目錄中有許多腳本都以deploy_ (例如, deploy_example.com )。
我通常一次通過調用./deploy_example.com來運行它們。

我該如何全部運行它們,一個又一個運行(如果可能,一次運行所有...)?

我試過了:

find deploy_* | xargs | bash

但這失敗了,因為這樣調用它需要絕對路徑。

您可以通過多種方式進行操作。 例如,您可以執行以下操作:

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

您可以簡單地執行以下操作:

for x in deploy*; do bash ./$x; done
find deploy_* | xargs -n 1 bash -c

將一個接一個地運行它們。 查看手冊頁中的xargs--max-procs設置,以獲取一定程度的並行性。

在子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
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM