From 3966eb53742c0cb3fed92106fb044444d6c46ba5 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Mon, 25 Jun 2018 11:13:41 -0700 Subject: [PATCH] support MacOS bash and ifconfig properly --- multinode-demo/myip.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/multinode-demo/myip.sh b/multinode-demo/myip.sh index 4ec054e7b88343..25ab4c72ff5247 100755 --- a/multinode-demo/myip.sh +++ b/multinode-demo/myip.sh @@ -2,16 +2,17 @@ function myip() { - declare ipaddrs=( ) - - # query interwebs - mapfile -t ipaddrs < <(curl -s ifconfig.co) - - # machine's interfaces - mapfile -t -O "${#ipaddrs[*]}" ipaddrs < \ - <(ifconfig | awk '/inet(6)? (addr:)?/ {print $2}') - - ipaddrs=( "${extips[@]}" "${ipaddrs[@]}" ) + # shellcheck disable=SC2207 + declare ipaddrs=( + # query interwebs + $(curl -s ifconfig.co) + # machine's interfaces + $(ifconfig | + awk '/inet addr:/ {gsub("addr:","",$2); print $2; next} + /inet6 addr:/ {gsub("/.*", "", $3); print $3; next} + /inet(6)? / {print $2}' + ) + ) if (( ! ${#ipaddrs[*]} )) then