Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Failed to capture the error message in linux

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading