Search code examples
bashshellsh

Can I mute the output of the curl command in the bash script below?


I am attempting to check if a connection can be made with the url in the script, not sure if that is the best approach. The curl command's output is all going to stdout. I only want my echo to go to stdout after running the script below. I tried adding -s, but that did not help. I would appreciate some help.

check=$(curl -s -vv -I https://github.com | grep "HTTP/2 200")
if [[ -z "$check" ]]; then
  echo "Cnxn failed"
else
  echo "Cnxn successful"
fi

I would like to see something like this only:

Cnxn failed

or

Cnxn successful

Solution

  • Please try this code

    check=$(curl -s -vv -I https://github.com 2>/dev/null | grep "HTTP/2 200")
    #echo $check
    if [[ -z $check ]] ; then
          echo "Cnxn failed"
        else
          echo "Cnxn successful"
    fi