Failed to capture the error message in linux

Advertisements

Failed to capture the response for the below command;

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

output:

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

I tried the above code snippet but still it’s catching the error. I want to suppress the error message , and have custom message as an output. like below

"Failed, please provide valid url"

>Solution :

Print stdout and stderr to /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

Leave a ReplyCancel reply