concatenate_with_commas.sh
· 503 B · Bash
Raw
#########################################
## Concatenate a list of arguments with commas
##
## Outputs:
## Outputs all arguments as a single string, concatenated with commas
#########################################
concatenate_with_commas() {
local concatenated=""
local string
for string in "$@"; do
if [[ "${concatenated}" == "" ]]; then
concatenated+="${string}"
else
concatenated+=",${string}"
fi
done
echo "${concatenated}"
}
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 | } |