title: Efficient way to get your IP address in shell scripts
body: <p><strong>Context:</strong>
  On *nix systems, one may get the IP address of the machine in a shell script this way:</p>
  
  <pre><code>ifconfig | grep 'inet' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}'
  </code></pre>
  
  <p>Or this way too:</p>
  
  <pre><code>ifconfig | grep 'inet' | grep -v '127.0.0.1' | awk '{print $2}' | sed 's/addr://'
  </code></pre>
  
  <p><strong>Question:</strong>
  Would there be a more straightforward, still portable, way to get the IP address for use in a shell script?</p>
  
  <p>(<a href="http://www.cyberciti.biz/tips/read-unixlinux-system-ip-address-in-a-shell-script.html" rel="noreferrer">my apologies to *BSD and Solaris users as the above command may not work</a>; I could not test)</p>