On 3/14/15, Le Manh Cuong <manhcuon...@hotmail.com> wrote: > In bash, you need to quote in second arr assignment: > $ arr=(a b c); IFS=+; arr="${arr[*]/a/x}"; echo "$arr"x+b+c > A note that the result from those shells are different. After second > assignment to arr: > - In bash and ksh, arr still be an array, contain 3 elements "x b c", "b", > "c" > ==bash== $ typeset | grep arr arr=([0]="x+b+c" [1]="b" [2]="c") > ==ksh==$ typeset | grep arrindexed array > - In zsh and yash, arr now is a string: > ==zsh==$ typeset | grep arrarr=x+b+c > ==yash== > $ typeset | grep arrtypeset arr='x+b+c' > -- Mr. LE Manh CuongMobile: +84 1216 181090Skype: manhcuongle> Date: Fri, 13 > Mar 2015 23:15:43 +0100 >> Subject: IFS is ignored when concatenating array elements >> From: izaber...@gmail.com >> To: bug-bash@gnu.org >> >> This works as I would expect: >> >> $ arr=(a b c); IFS=+; echo "${arr[*]/a/x}" >> x+b+c >> >> >> But for some reason, this ignores IFS: >> >> $ arr=(a b c); IFS=+; arr=${arr[*]/a/x}; echo "$arr" >> x b c >> >> >> >> >> Here is the behaviour of other shells that allow that kind of syntax: >> >> input: arr=(a b c); IFS=+; echo "${arr[*]/a/x}" >> ======================= >> bash: x+b+c >> ksh: x+b+c >> yash: x+b+c >> zsh: x+b+c >> >> input: arr=(a b c); IFS=+; arr=${arr[*]/a/x}; echo "$arr" >> ======================= >> bash: x b c >> ksh: x+b+c >> yash: x+b+c >> zsh: x+b+c >> >
(I'm sending your message to the mailing list too) Well, I just find it weird that quotes aren't needed in this case: $ arr=(a b c); IFS=+; arr=${arr[*]}; echo "$arr" a+b+c but they are in this case: $ arr=(a b c); IFS=+; arr=${arr[*]/a/x}; echo "$arr" x b c But apparently that's a recent addition, since 4.2 and below still ignore IFS: 4.2$ arr=(a b c); IFS=+; arr=${arr[*]}; echo "$arr" a b c I just thought it would be nice to have a consistent behaviour. --- xoxo, iza