未能捕獲以下命令的回應;
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"
uj5u.com熱心網友回復:
將標準輸出和標準錯誤列印到/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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/473080.html
上一篇:如何找到迭代回圈期間花費的時間?
