Skip to content

Instantly share code, notes, and snippets.

@kaniblu
Created September 23, 2020 03:53
Show Gist options
  • Save kaniblu/19c60cfe01d3a709a97909f58d95cdcb to your computer and use it in GitHub Desktop.
Save kaniblu/19c60cfe01d3a709a97909f58d95cdcb to your computer and use it in GitHub Desktop.
join_by () {
# Argument #1 is the separator. It can be multi-character.
# Argument #2, 3, and so on, are the elements to be joined.
# Usage: join_by ", " "${array[@]}"
local SEPARATOR="$1"
shift
local F=0
for x in "$@"
do
if [[ F -eq 1 ]]
then
echo -n "$SEPARATOR"
else
F=1
fi
echo -n "$x"
done
echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment