无法捕获 linux 中的错误消息

Failed to capture the error message in linux

无法捕获以下命令的响应;

URL="https://gsdfdsfithub.com/gitexpert/testGithub.git" > /dev/null 

git ls-remote $URL -q

if [ $? -nq 0 ]; then
    echo "Failed, please provide valid url"
fi

输出:

fatal: unable to access 'https://gsdfdsfithub.com/gitexpert/testGithub.git/': Received HTTP code 404 from proxy after CONNECT
128
line 4: [: -nq: binary operator expected

我尝试了上面的代码片段,但它仍然捕获错误。我想抑制错误消息,并将自定义消息作为输出。如下图

"Failed, please provide valid url"

将 stdout 和 stderr 打印到 /dev/null

URL="https://gsdfdsfithub.com/gitexpert/testGithub.git" > /dev/null 

git ls-remote $URL -q >> /dev/null 2>&1

if [ $? != 0 ]; then
    echo "Failed, please provide valid url"
fi