【问题标题】:call a bash script from a bash script and wait for it to get over and continue从 bash 脚本调用 bash 脚本并等待它结束并继续
【发布时间】:2014-07-16 18:30:37
【问题描述】:

我只想执行“CloneBUildInstall.sh”、“MonkeyTest.sh”和“SilentException.sh”.. 我不会去采购它。我怎样才能简单地执行它。

adb devices > output.txt

调用脚本

while :
do
. CloneBuildInstall.sh

不要来源。只需执行...我该怎么做?

    echo "Clone, Build and Install script is finished."

. MonkeyTest.sh & . SilentException.sh &
    echo "Monkey Test script and Silent Exception is finished."
done

【问题讨论】:

  • 试试bash CloneBuildInstall.sh
  • @AvinashRaj 它会等待它运行然后执行?

标签: bash shell ubuntu scripting


【解决方案1】:

除了使用 shell 的二进制文件再次调用它们之外,您还可以在显然更容易和更清洁的子 shell 中运行它们:

( . MonkeyTest.sh )
( . SilentException.sh )

如果您打算并行运行它们,等待它们完成会很复杂。

( . MonkeyTest.sh ) &
MPID=$!
( . SilentException.sh ) &
SPID=$!

wait "$MPID"; wait "$SPID"  ## Just basic.

【讨论】:

  • 但来源和 .具有相同的含义...我只想执行 CloneBuildInstall.sh 并等到它结束并从它所在的位置继续。
  • @user3738506 source-ing 在同一上下文中(不是在子shell 上)会改变shell 的环境并影响它。但是在子shell 上运行它会在不同的进程上运行它——并且类似于运行sh /path/to/your/script.sh 只是使用子shell 方法,你确定你运行的是同一个shell。
  • 所以。 MonkeyTest.sh 只是在执行它?...不是采购?
【解决方案2】:

一种方法是像在命令行上一样指定它,但这需要一个相对路径到您运行命令的位置。

./MonkeyTest.sh && ./SilentException.sh

另一种方法是硬编码完整路径。

/full/path/to/MonkeyTest.sh && /full/path/to/SilentException.sh

【讨论】:

  • 但来源和 .具有相同的含义...我只想执行 CloneBuildInstall.sh 并等到它结束并从它所在的位置继续。
  • @user3738506 采购 - . CloneBuildInstall.sh,执行 - ./CloneBuildInstall.sh。我想你明白了。
  • 但是这个脚本已经在后台启动了它们。他们还没有完成。我想知道脚本什么时候完成,以便我可以做其他任务
  • @user3738506,不,脚本不会在后台运行它们,除非MonkeyTest.sh 或SilentException.sh 被编写为自己启动后台进程。
  • && != &。 x && y 运行 x,然后仅在 x 成功时运行 y。
猜你喜欢
  • 1970-01-01
  • 2015-04-24
  • 1970-01-01
  • 1970-01-01
  • 2017-05-30
  • 1970-01-01
  • 2017-10-11
  • 2023-04-07
  • 2012-07-23
相关资源
最近更新 更多