Bash pip搜索检查版本包含在标准输出中

问题描述 投票:0回答:1

我正在尝试进行点子搜索。

pip search --index https://obfuscated/python-release docker-client

这将返回docker-client (1.3.0) - Client library for Docker Pipeline - 0f7f2d821d09db2f268281c84e298967a6df4b11

我希望能够搜索输出字符串以匹配我的bash脚本中的版本。例如,我希望grep该标准,以确保它确实是1.3.0版本。我将如何在下面的bash脚本中进行此操作。

set -e
if pip search --index https://obfuscated/python-release docker-client; then
    echo " hello world"
fi
`));
bash pip
1个回答
1
投票

你可以这样做:

#!/bin/bash

version='1.3.0'

if [ $(pip search --index https://obfuscated/python-release docker-client | grep -c $version) -eq 1 ]
then
    echo "OK version $version it is."
else
    echo "ERROR: pip failure, or wrong version."
fi

显然,如果版本号不会出现在整个地方,这将起作用。防爆。如果pip返回( 1.3.4, upgrade from 1.3.0 )它将无法正常工作。您将不得不解决输出格式,但根据您提供的内容,这将起作用。

© www.soinside.com 2019 - 2024. All rights reserved.