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

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
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 Wed, 1 Aug 2018 14:43:27 +0300
Lines 39
Approved bug-bash@gnu.org
Message-ID <mailman.4533.1533123823.1292.bug-bash@gnu.org> (permalink)
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1533123823 32713 208.118.235.17 (1 Aug 2018 11:43:43 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
Content-Language en-US
X-SASI-RCODE 200
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; h=to:from:subject:message-id:date:mime-version:content-type:content-transfer-encoding; s=smtp; bh=KwTtMluveVVR4hwgwxAveYNtSF5fJmW/z79w9cOEm7Q=; b=in2pMNMwAg9zXaJbbNPmv182px1B/IUybx/Zeo8IIhmDgD/nCQtHIkAax/2gy9682Q9S52MNNbJhxtkFuQxuxh7QwvJ5oX6X8j68S3TVSZAo2kb0x3D9eTzPKPLQypaw6+ahb8uTciPP4qF7kUarwe1FUTCftP0Nk+D6i5U/AHtNwH8oa9+2JkeVEvWf1rimmWdNNx6GItUUD6M4XBjGRqnaYJnek9Ez3kP9Pgp92LI+lXA7rAzVyacr2vJPrRtNZ4Y7h+KRW3VDGXKNjYOK0pghs2ZLqwoSpp8M2Gi/GYHNUFouXF9Z+9dhVle+9kgsUbGXZ46Xra/9GeTGg7LcsA==
X-detected-operating-system by eggs.gnu.org: FreeBSD 8.x [fuzzy]
X-Received-From 157.24.2.213
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14427

Show key headers only | 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