bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

="${@:...}" and ="${@/...}" join with IFS since after 4.4


From: Emanuele Torre
Subject: ="${@:...}" and ="${@/...}" join with IFS since after 4.4
Date: Sun, 16 Nov 2025 01:23:35 +0100
User-agent: Mutt/2.2.14 (2025-02-20)

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

[Prev in Thread] Current Thread [Next in Thread]