Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14431
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Ilkka Virta <itvirta@iki.fi> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space |
| Date | Wed, 1 Aug 2018 16:06:03 +0300 |
| Lines | 58 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.4550.1533128777.1292.bug-bash@gnu.org> (permalink) |
| References | <c1978119-1836-e88d-4889-c54bea4d0559@iki.fi> <20180801121251.efyquoibrsneiqbl@eeg.ccf.org> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | usenet.stanford.edu 1533128778 3081 208.118.235.17 (1 Aug 2018 13:06:18 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | 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 |
| In-Reply-To | <20180801121251.efyquoibrsneiqbl@eeg.ccf.org> |
| Content-Language | en-US |
| X-SASI-RCODE | 200 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; h=subject:to:references:from:message-id:date:mime-version:in-reply-to:content-type:content-transfer-encoding; s=smtp; bh=pvMc0HEW/UUdf8buDOwEQY4JE4IsfzCXcWNe6axZqaI=; b=sZTlDuO7IAZB2enm6s3K36r46mlokdNM9jfOBjcOH3dlpJVtE14CiEpjLD7Ny90SngkTsOMeEihyK0ilcCzCzvTgVeDJdjjXeICRZBEyyhMwERr3dD66j1NqiQS++yFz80hUQCNv6cWk5Ggs2owTIs64KFkY/tjJoDU4xdFpXI8fNvX4fbM5WJbBGx1Y47Mhq9SgIpL/DGZvmn9BQPMZB/izjmW5tysqeFtIhWMBlpTEsii3Qj8a6NnPdqbXTcbcY3qHD9rq28wyuhG1wPi34JgtsTk+pBVb1N0kL7hzJpVKMaCVKwvT7mbhpAPCYIEJuikFaihuXjGu/Rlfv5xCJQ== |
| 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:14431 |
Show key headers only | View raw
On 1.8. 15:12, Greg Wooledge wrote:
> On Wed, Aug 01, 2018 at 02:43:27PM +0300, Ilkka Virta wrote:
>> 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):
>
> This just reinforces the point that unquoted $@ or $* (or the array
> equivalent) is a bug in the script. It gives unpredictable results.
Unquoted $* seems well-defined in Bash's reference manual:
($*) Expands to the positional parameters, starting from one. When the
expansion is not within double quotes, each positional parameter
expands to a separate word.
The reference doesn't really say anything about an unquoted $@, but then
there's the POSIX definition which should be well-defined in this case,
since clearly field-splitting should be performed here.
@: Expands to the positional parameters, starting from one, initially
producing one field for each positional parameter that is set. When
the expansion occurs in a context where field splitting will be
performed, any empty fields may be discarded and each of the non-empty
fields shall be further split as described in Field Splitting.
Now, of course POSIX doesn't say anything about arrays or the
subarray/slice notation, but then Bash's reference mentions that
[@] and [*] are supposed to be analoguous to $@ and $*, and the
description of ${parameter:offset:length} doesn't say that
${array[@]:n:m} would act differently from ${array[@]} let alone
differently from ${@:n:m}.
Instead, the wording of the subarray/slice expansion is similar for both
${@:n:m} and ${array[@]:n:m}:
${parameter:offset:length}
If parameter is ‘@’, the result is length positional parameters
beginning at offset.
If parameter is an indexed array name subscripted by ‘@’ or ‘*’, the
result is the length members of the array beginning with
${parameter[offset]}.
It doesn't say what's done with those parameters or array members, but
if the behaviour is supposed to be different between these two cases,
it's not documented.
--
Ilkka Virta / itvirta@iki.fi
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: 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 16:06 +0300
csiph-web