support MacOS bash and ifconfig properly

This commit is contained in:
Rob Walker 2018-06-25 11:13:41 -07:00 committed by Greg Fitzgerald
parent c22ef50cae
commit 3966eb5374

View File

@ -2,16 +2,17 @@
function myip() function myip()
{ {
declare ipaddrs=( ) # shellcheck disable=SC2207
declare ipaddrs=(
# query interwebs # query interwebs
mapfile -t ipaddrs < <(curl -s ifconfig.co) $(curl -s ifconfig.co)
# machine's interfaces
# machine's interfaces $(ifconfig |
mapfile -t -O "${#ipaddrs[*]}" ipaddrs < \ awk '/inet addr:/ {gsub("addr:","",$2); print $2; next}
<(ifconfig | awk '/inet(6)? (addr:)?/ {print $2}') /inet6 addr:/ {gsub("/.*", "", $3); print $3; next}
/inet(6)? / {print $2}'
ipaddrs=( "${extips[@]}" "${ipaddrs[@]}" ) )
)
if (( ! ${#ipaddrs[*]} )) if (( ! ${#ipaddrs[*]} ))
then then