Normally "$@"/"${arr[@]}" on the RHS side of an assignment joins the
elements with ' ' even if IFS is set to a string with a first character
that is not space.

However, as it has been pointed out today in the #bash IRC channel on
libera.chat, IFS seems to be used instead when the ${@/} parameter
expansion is used and is quoted.

    bash-5.3$ set a b c; IFS=: o=${@/}; declare -p o
    declare -- o="a b c"
    bash-5.3$ set a b c; IFS=: o="${@/}"; declare -p o
    declare -- o="a:b:c"

Also when "${@:}" is used:

    bash-5.3$ set a b c; IFS=: o=${@:1}; declare -p o
    declare -- o="a b c"
    bash-5.3$ set a b c; IFS=: o="${@:1}"; declare -p o
    declare -- o="a:b:c"

Additionally, ${@@Q} always uses IFS regardless of whether it is quoted
or not:

    $ set a b c; IFS=: o=${@@Q}; declare -p o
    declare -- o="'a':'b':'c'"
    $ set a b c; IFS=: o="${@@Q}"; declare -p o
    declare -- o="'a':'b':'c'"

This behaviour changed at some point after bash 4.4: in bash 4.4, they
all always used ' ' to join the elements of $@/${arr[@]} in assignment
regardless of whether they were quoted or not; also ${@@Q}.

I would expect them to use ' ' to join these elements since this seems
to only occur for ${@/...} and ${@:...} and only when they are quoted in
assignments. And I would expect ${@@Q} to use space as well.

o/
 emanuele6

Reply via email to