| 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 | } |
matthew / Bash Comma Concatenation
Last active 2 weeks ago
Concatenate a list of arguments into a string using a comma separator