Last active 1729621685

Concatenate a list of arguments into a string using a comma separator

matthew's Avatar matthew revised this gist 1729621685. Go to revision

No changes

matthew's Avatar Matthew Weier O'Phinney revised this gist 1666360496. Go to revision

1 file changed, 20 insertions

concatenate_with_commas.sh(file created)

@@ -0,0 +1,20 @@
1 + #########################################
2 + ## Concatenate a list of arguments with commas
3 + ##
4 + ## Outputs:
5 + ## Outputs all arguments as a single string, concatenated with commas
6 + #########################################
7 + concatenate_with_commas() {
8 + local concatenated=""
9 + local string
10 +
11 + for string in "$@"; do
12 + if [[ "${concatenated}" == "" ]]; then
13 + concatenated+="${string}"
14 + else
15 + concatenated+=",${string}"
16 + fi
17 + done
18 +
19 + echo "${concatenated}"
20 + }
Newer Older