[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Array parameter expansion with non-space-IFS on bash-3/4
From: |
DennisW |
Subject: |
Re: Array parameter expansion with non-space-IFS on bash-3/4 |
Date: |
Sun, 29 Nov 2009 06:55:33 -0800 (PST) |
User-agent: |
G2/1.0 |
On Nov 27, 3:47 pm, Freddy Vulto <fvu...@gmail.com> wrote:
> I noticed different behaviour between bash-3 and bash-4 when
> performing parameter expansion on an array with IFS set to a non-space
> value. For example, on bash-3.2.39, I get:
>
> $ bash -c 'IFS=:; printf "<%s>\n" "${@/q}"' x a b
> <a b>
>
> Whereas on bash-4.0.33, I get:
>
> $ bash -c 'IFS=:; printf "<%s>\n" "${@/q}"' x a b
> <a>
> <b>
>
> Bash-4 seems to give the desired result (leave the array intact), but
> it's a bug on bash-3?
>
> Regards,
>
> Freddy Vultohttp://fvue.nl
It seems to be a combination of IFS and pattern substitution. There's
another difference shown below with an intact IFS, but referring to a
string as an array.
Using this script:
#!/bin/bash
v=(a b c)
w="d e f"
printf "<%s>\n" "${w[@]/q}"
IFS=X
printf "<%s>\n" "${v[@]/q}"
In Bash 4.0.33(1)-release I get:
<d e f>
<a>
<b>
<c>
In Bash 3.2.49(23)-release I get:
<d>
<e>
<f>
<a b c>
Other combinations of array vs. string, changing IFS or not, and/or
not using pattern substitution produce the same results in the two
versions.
----
Dennis
sysadmins: visit serverfault.com