Last active
February 23, 2016 09:01
-
-
Save WalterS/3331cf7753af9cf995b6 to your computer and use it in GitHub Desktop.
Useless use of grep etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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