如何在 shell 脚本中检测 php xdebug

How to detect php xdebug in shell script

基本上,如果 php 安装了 xdebug,我想 运行 启用代码覆盖测试。否则只是 运行 没有代码覆盖的测试。像这样:

if [[ <detect xdebug> ]]; then coverage="--coverage-xml"; fi
vendor/bin/codecept run $coverage

使用

很容易知道是否启用了xdebug
php -v | grep Xdebug

如果此命令returns 某些 xdebug 已启用,否则它不可用。

我只是不知道如何在 if 中使用它。

if php -v | grep -q 'Xdebug'; then
  echo "Xdebug installed"
fi