Skip to content

Instantly share code, notes, and snippets.

@ktchernov
Last active June 9, 2022 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktchernov/55b37589a97a9ef58e6f3e1dcef41c69 to your computer and use it in GitHub Desktop.
Save ktchernov/55b37589a97a9ef58e6f3e1dcef41c69 to your computer and use it in GitHub Desktop.
Bash array join
# 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