gpt4 book ai didi

php - 脚本调用后 Bash 不继续?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:03 28 4
gpt4 key购买 nike

我有两个 bash 脚本。一个运行得非常好,直到它到达另一个脚本的调用,然后它执行那个脚本很好但永远不会在原始脚本中继续,我不确定如何解决这个问题。

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

如果目录是 Loader、Routes 或 Loop,我们将输入这些目录并在该目录中运行脚本。

让我们看看 run-tests 脚本:

#!/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 - 您可能只是在错误的目录中。

关于php - 脚本调用后 Bash 不继续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29937234/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com