Skip to content

Instantly share code, notes, and snippets.

@TGWolf
Last active September 26, 2015 16:25
Show Gist options
  • Save TGWolf/1db199c380de7cb8d43a to your computer and use it in GitHub Desktop.
Save TGWolf/1db199c380de7cb8d43a to your computer and use it in GitHub Desktop.
How to get the IP address programmatically from an interface name in bash.

How to get the IP address programmatically from an interface name in bash.

#!/bin/bash
IP=`/sbin/ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
echo $IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment