title: What does "$?" give us exactly in a shell script?
body: <p>I saw the code written somewhere online, and I wanted to know what exactly does "$?" do/give us.
  Googling did not help.</p>
  
  <p>Here's the code I saw it in:</p>
  
  <pre><code>#!/bin/sh
  
  ping -c 2 localhost
  if [ $? != 0 ] ; then
      echo "Couldn't ping localhost, weird"
      fi
  
  ping -c 2 veryweirdhostname.noend 
  if [ $? != 0 ] ; then
      echo "Surprise, Couldn't ping a very weird hostname.."
      fi
  
  echo "The pid of this process is $$"
  </code></pre>
  
  <p>Taken from: <a href="http://efod.se/writings/linuxbook/html/shell-scripts.html" rel="noreferrer">http://efod.se/writings/linuxbook/html/shell-scripts.html</a></p>