Skip to content

Instantly share code, notes, and snippets.

@Mausy5043
Created May 6, 2018 09:34
Show Gist options
  • Save Mausy5043/f82da8e0bfd0cc28c774b2d1d0903b0b to your computer and use it in GitHub Desktop.
Save Mausy5043/f82da8e0bfd0cc28c774b2d1d0903b0b to your computer and use it in GitHub Desktop.
Print IP of local machine
#!/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