Created
October 21, 2022 13:54
-
-
Save weierophinney/ae887d4f9339aedaaa9f8fef4bd5798f to your computer and use it in GitHub Desktop.
Concatenate a list of strings using a comma in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################### | |
## 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}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment