Skip to content

Instantly share code, notes, and snippets.

@WalterS
Last active February 23, 2016 09:01
Show Gist options
  • Save WalterS/3331cf7753af9cf995b6 to your computer and use it in GitHub Desktop.
Save WalterS/3331cf7753af9cf995b6 to your computer and use it in GitHub Desktop.
Useless use of grep etc.
Bad examples:
http://colby.id.au/finding-the-local-ip-address-with-ifconfig-and-sed/
http://www.cyberciti.biz/tips/read-unixlinux-system-ip-address-in-a-shell-script.html
Better:
All except loopback:
ip -o a | awk -F': +| +|/' '$2 != "lo" {print $4}'
Just eth0:
ip -o a | awk -F': +| +|/' '$2 == "eth0" {print $4}'
ip -o addr show dev eth0 | awk -F': +| +|/' '{print $4}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment