Last active 1729621685

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

concatenate_with_commas.sh Raw
1#########################################
2## Concatenate a list of arguments with commas
3##
4## Outputs:
5## Outputs all arguments as a single string, concatenated with commas
6#########################################
7concatenate_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}