Php 脚本调用后Bash不继续?

Php 脚本调用后Bash不继续?,php,linux,bash,shell,Php,Linux,Bash,Shell,我有两个bash脚本。一个运行得非常好,直到调用另一个脚本为止,然后它会很好地执行该脚本,但永远不会在原始脚本中继续,我不知道如何解决该问题 此脚本在特定目录的每个文件夹中运行测试。每个子文件夹都包含一个phpunit.xml文件,当我们进入每个文件夹时,我们会运行composer install和phpunit 如果目录是,Loader,Routes或Loop,那么我们将输入它们并在该目录中运行脚本 让我们看看运行测试脚本: #!/usr/bin/env bash set -e funct

我有两个bash脚本。一个运行得非常好,直到调用另一个脚本为止,然后它会很好地执行该脚本,但永远不会在原始脚本中继续,我不知道如何解决该问题

此脚本在特定目录的每个文件夹中运行测试。每个子文件夹都包含一个phpunit.xml文件,当我们进入每个文件夹时,我们会运行
composer install
phpunit

如果目录是,Loader,Routes或Loop,那么我们将输入它们并在该目录中运行脚本

让我们看看
运行测试
脚本:

#!/usr/bin/env bash

set -e

function run_tests() {
  if [[ -f "composer.json" ]] && [[ -f "phpunit.xml" ]]; then
    if [[ -d "vendor" ]]; then
      composer update
      phpunit > /dev/null
      phpunit
      cd ../
    else
      composer install
      phpunit > /dev/null
      phpunit
      cd ../
    fi
  else
    cd ../
  fi
}

for f in *; do
  if [[ -d $f ]]; then
    if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; then
      cd "$f/"

      if [[ $f == "Loader" ]]; then
        if [[ -d "Assets" ]]; then
          cd Assets/
          chmod +x asset-test
          ./asset-test
        fi
      fi

      if [[ $f == "Loop" ]]; then
        cd Loop/
        chmod +x loop-test
        ./loop-test
        cd ../
      fi

      if [[ $f == "Routes" ]]; then
        cd Routes/
        chmod +x routes-test
        ./routes-test
        cd ../
      fi

      run_tests
    fi
  fi
done

# Go Home.
cd /vagrant/Freya/

## Clean up time!
## Remove all vendor and composer.lock folders - just because.
for f in *; do
  if [[ -d $f ]]; then
    if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; then
      cd "$f/"
      rm -rf vendor composer.lock
      cd ../
    fi
  fi
done
我们可以看到,一旦它进入检查以查看我们所在的目录是否为“Loops”,我们就会检查里面是否有一个名为“Assets”的目录。假设此过程已通过,则进入该目录并运行下一个脚本:

#!/usr/bin/env bash

set -e

# Run Composer Install if vendor doesnt exist.
if [[ -d "vendor" ]]; then
  composer update
else
  composer install
fi

# Move up to the root directories and then get wordpress
cd ../../../

# Determine if the trunk is checked out and if we have a wp-test-config.php
# If not we need to create both or one or the other then run the tests.
#
# We run phpunit twice because the second time is when it actually runs.
if [[ -d "trunk" ]]; then
  cd "trunk/"
  if [[ -f "wp-tests-config.php" ]]; then
    cd ../Freya/Loader/Assets
    phpunit > /dev/null
    phpunit
  else
    cd ../Freya/Loader/Assets
    cp wp-tests-config.php ../../trunk/
    phpunit > /dev/null
    phpunit
  fi
else
  sudo svn co http://develop.svn.wordpress.org/trunk/
  cd Freya/Loader/Assets
  cp wp-tests-config.php ../../trunk/
  phpunit > /dev/null
  phpunit
fi
问题是,一旦这个脚本完成,我发布的第一个脚本的其余部分就永远不会继续了。就像它在这里死去一样。我需要的是“父”脚本要完成,它应该退出
Loader/Assets
,并继续进行下一次检查。但事实并非如此。脚本只是存在

为什么?

注意:在第二个脚本中,我们可以假设它进入第一个嵌套的if语句,在该语句中检查主干目录中的
wp tests config.php
我们可以假设这一点,因为以下输出是从运行第一个脚本中捕获的:

$ bin/run-tests 
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Exceptions/phpunit.xml

.

Time: 451 ms, Memory: 13.25Mb

OK (1 test, 1 assertion)
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Factory/phpunit.xml

...........

Time: 711 ms, Memory: 13.25Mb

OK (11 tests, 11 assertions)
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing freya/freya-templates (dev-master a33ecdb)
    Cloning a33ecdb231b06dc8a7eef363edb177b8c134d55b

Writing lock file
Generating autoload files
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Form/phpunit.xml

...............................................................

Time: 647 ms, Memory: 15.25Mb

OK (63 tests, 63 assertions)
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Loader/Assets/phpunit.xml

...........

Time: 1.76 seconds, Memory: 38.00Mb

OK (11 tests, 11 assertions)
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Loader/Assets/phpunit.xml

...........

Time: 1.79 seconds, Memory: 38.00Mb
我们在这里可以看到两个问题:

  • /vagrant/Freya/Loader/Assets/
    运行两次
  • 它从未在第一个脚本中继续

    • 如果没有在您的机器上进行所有设置,则很难进行远程调试。要获得更有用的答案,可以先尝试通过依次禁用部分代码来隔离问题。我可以看出,在你的情况下,这可能很困难

      以下是调试的一些想法:

      • 这两个脚本都使用
        set-e
        运行,即它们将在第一个命令(包括第二个脚本)以非零退出代码终止时退出。尝试添加
        set-x
        ,查看最后执行的命令
      • 您有很多相关的
        cd
        调用。在上一步中识别的最后一个命令之前尝试
        pwd
        ——您可能只是在错误的目录中

      尽量举一个简单的例子,因为大多数人不愿意通读所有这些,所以你不太可能得到答案。JID++。您可能会发现,在将脚本压缩到最小示例的过程中,您自己也会发现问题!