我怎样才能幂等地 pecl 安装一个模块两次?

spr*_*aff 3 linux bash pecl

我有一个应该可以重新运行的 bash 脚本。这包括

pecl install foo ||
{
    echo "Could not install foo!";
    exit 1;
}
Run Code Online (Sandbox Code Playgroud)

如果这运行两次,它会出错

pecl/foo is already installed and is the same as the released version 1.2.3
install failed
Could not install foo!
Run Code Online (Sandbox Code Playgroud)

与 apt-get 或 yum 等工具不同,如果模块已安装,pecl 会返回错误代码,而我希望它报告成功。

我可以捕获和 grep stdout/stderr 但是有没有更简单的方法来实现相同的目标?

spr*_*aff 5

if ! pecl list | grep foo >/dev/null 2>&1;
then
    pecl install foo ||
    {
        echo_err "Could not pecl install foo";
        exit 1;
    }
fi
Run Code Online (Sandbox Code Playgroud)