Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14427 > unrolled thread
| Started by | Ilkka Virta <itvirta@iki.fi> |
|---|---|
| First post | 2018-08-01 14:43 +0300 |
| Last post | 2018-08-01 14:43 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space Ilkka Virta <itvirta@iki.fi> - 2018-08-01 14:43 +0300
| From | Ilkka Virta <itvirta@iki.fi> |
|---|---|
| Date | 2018-08-01 14:43 +0300 |
| Subject | Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space |
| Message-ID | <mailman.4533.1533123823.1292.bug-bash@gnu.org> |
On both Bash 4.4.12(1)-release and 5.0.0(1)-alpha, a subarray slice like
${a[@]:0} expands to just one word if unquoted (and if IFS doesn't
contain a space):
$ a=(aa bb); IFS=x; printf ":%s:\n" ${a[@]:0}
:aa bb:
I expected it would expand to separate words, as it does without the
slice, and just like $@ does, sliced or not:
$ a=(aa bb); IFS=x; printf ":%s:\n" ${a[@]}
:aa:
:bb:
$ set -- aa bb; IFS=x; printf ":%s:\n" $@
:aa:
:bb:
$ set -- aa bb; IFS=x; printf ":%s:\n" ${@:1}
:aa:
:bb:
It's as if it first joins the picked elements with spaces, and then
splits using IFS, instead of producing multiple words and word-splitting
them individually.
The same thing happens with ${a[*]:0} (but not with ${*:1}):
the array elements get joined with spaces to a single word. If IFS is
empty, unset, or contains a space the result is multiple words as
expected with both [@] and [*].
An expansion like that should in most cases be quoted,
but the current behaviour still seems a bit inconsistent.
--
Ilkka Virta / itvirta@iki.fi
Back to top | Article view | gnu.bash.bug
csiph-web