title: Return value of ping
body: <p>I have done a file named hosts.txt which includes some websites, to test the ping on each website with a script. What I want to do with my script is I want to loop through each line that includes different websites, and it should tell if the website is up or down (by measuring the ping command on each)</p>
  
  <p>What my problem is that I don't really know how to get the return value of the ping command, so in case a website is up it should say "'website name' found" or not found. I have been researching, also tried out the ! command and different ways in the if-statement, but none of them seem to work. </p>
  
  <p>My code:</p>
  
  <pre><code>#!/bin/bash
  echo
  echo "Monitoring hosts from file hosts.txt ..."
  echo
  echo
  egrep -v '^(#|$)' hosts.txt | while read line; do #put the egrep value
  #which is the lines in hosts.txt, and loop through each one of them
  
          if [ ping $line ];then
          echo "$line is up"
  
          else
          echo "$line is not up"
          fi
  
  done
  
  echo
  </code></pre>