Home > other >  Linux terminal ping but only True/False
Linux terminal ping but only True/False

Time:01-29

How can I test the accessibility of the web address with ping command but so that it only returns True or False? Similar to PowerShell's

Test-Connection -ComputerName address.com -Quiet

I googled it but that's it.

CodePudding user response:

ping -c1 address.com >/dev/null 2>&1

This issues one ping, doesn't output anything, and returns a 0/true if it worked, a positive error code if it failed, to the shell.

You can query it with echo $?.

If you just need to use the positive result:

if ping -c1 address.com >/dev/null 2>&1 ; then
    echo Yup
fi
  • Related