Last active
June 9, 2022 22:16
-
-
Save ktchernov/55b37589a97a9ef58e6f3e1dcef41c69 to your computer and use it in GitHub Desktop.
Bash array join
This file contains 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
# turns a port and an IP array into a string like: "127.0.0.1:4430,10.33.0.6:4430" | |
function ip_list_with_ports { | |
local port=$1 | |
shift 1 | |
local ips=("$@") | |
for ((i=0; i<${#ips[@]}; i++)); do | |
echo -n "${ips[$i]}:$port" | |
if [ $i != $(( ${#ips[@]} - 1 )) ]; then | |
echo -n "," | |
fi | |
done | |
} | |
# usage | |
ip_list_with_ports 4430 ${node_ips[@]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment