matthew revised this gist . Go to revision
No changes
Matthew Weier O'Phinney revised this gist . 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