Created
May 6, 2018 09:34
-
-
Save Mausy5043/f82da8e0bfd0cc28c774b2d1d0903b0b to your computer and use it in GitHub Desktop.
Print IP of local machine
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
#!/bin/bash | |
getMyIP() { | |
local _ip _line | |
while IFS=$': \t' read -a _line ;do | |
[ -z "${_line%inet}" ] && | |
_ip=${_line[${#_line[1]}>4?1:2]} && | |
[ "${_ip#127.0.0.1}" ] && echo $_ip && return 0 | |
done< <(LANG=C /sbin/ifconfig) | |
} | |
getMyIP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment