Q:

How to join arguments with a separator?

In bash, how to join arguments of a function into a single string?
The seperator is fixed, and is not space (thus "$*" is not what I want). Here use ", " as example.
join_args() {
# join args with sep ", ", then echo the joined string
# ... code here
}

join_args abc def ghi
# abc, def, ghi

A:

$* can work with characters other than space if you set $IFS, but it can only use one character. Thus
join_args() {
    local IFS=', '
    echo "${*}"
}

outputs abc,def,ghi.
If you need longer separators, you have to use a loop:
join_args() {
    while (($# > 1)) ; do
        printf '%s, ' "$1"
        shift
    done
    if (($#)) ; then
        printf '%s\n' "$1"
    fi
}

Or, use a real programming language:
perl -E 'say join ", ", @ARGV' abc def ghi

