Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14427

Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space

From Ilkka Virta <itvirta@iki.fi>
Newsgroups gnu.bash.bug
Subject Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space
Date 2018-08-01 14:43 +0300
Message-ID <mailman.4533.1533123823.1292.bug-bash@gnu.org> (permalink)

Show all headers | View raw


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 gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web