Created
September 23, 2020 03:53
-
-
Save kaniblu/19c60cfe01d3a709a97909f58d95cdcb to your computer and use it in GitHub Desktop.
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
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