Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15841
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Clint Hepner <clint.hepner@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: read and inconsistent handling of trailing null field? |
| Date | Wed, 29 Jan 2020 10:46:00 -0500 |
| Lines | 68 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.38.1580312750.2384.bug-bash@gnu.org> (permalink) |
| References | <122693AD-B562-43A5-BE64-58B02C72B6EA@gmail.com> <f6382f38-add8-731a-6d47-77d292d013c8@case.edu> <A1A301FD-7C11-4F0F-84D1-299CCF10F8D3@gmail.com> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\)) |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | usenet.stanford.edu 1580312750 13323 209.51.188.17 (29 Jan 2020 15:45:50 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | "bash.bug list" <bug-bash@gnu.org> |
| To | chet.ramey@case.edu |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CH6X+BYHrBr17PdFzAJRFvB/CAmmH75XW4EDoYJ3npI=; b=mp9dAFk56q6yNH+5Eh5Bw4yFNR3hKcMxmM4pxSVIQZ8msz6TVMCWacnyIw06QNMaL3 QIgvc8UBLd3G1oM0BedIyS+z9yteSGSb9UvZwAJK4TJpEbaINkxdZekwwkTP4Bng6MDn /J1Oi2bhXyib1dm2k75t5P3KogahI59eR/ShIOsEAz/N0f3KVAUg7Yk2hGa4nCZl5ma8 nEuKz+X+qId73BVo4tKo9/EAa4427WNwOeS/amsc7gGs0cURsIlEao/HHig3GLRf60y7 Ea109RsFeNMDqlajJNqMbeTaGtLBJze51pmMSuscFEtDyt7JHUScHfPf+sotdlaFQ/v6 vO4Q== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CH6X+BYHrBr17PdFzAJRFvB/CAmmH75XW4EDoYJ3npI=; b=c+FIwTBX6K+ML9tnEsuwDRslJ3i2bbicRR9Ysnui9l/DhkiaFqyczaATZ9pQtJFE39 7i9fZbWkxfm2c6GtrYz+/X3vaVClJdXojisiQdd/u2IIwCp4d9nYY1B1+FtIXFvgmMTK V50Qs6ywv5Rcbw8MBqjJe/pN+lbA2eEKbKJQrfbYYc5DfLYHsMeNqRfR7mtxg5Vc9dRt 7j7dL2v/uo9zNQ8ax5Hp3RUnVyw7znELc+icebbT7bqkD5FJhz3StPCXE8WviKrqakjx 1xklmIRK3w4r1J2OsJZ6oPl/epGYACn1uT4exbSXrO7pUMW0m41AW2/EXFbjiBj5GY96 PHCQ== |
| X-Gm-Message-State | APjAAAWXsdUd0sqV2umOr0k1Q8/1RtdPZpZqCmBfpDHX2cIEHT6clIyi VPFMITtvZdK70ieZLagfeLs= |
| X-Google-Smtp-Source | APXvYqy/vOh/+1IIN/tNIYac0ceYJGo784WFBa7+WiKcGrieZZTuJQTr/pFfd/Bm2//GVe1XUqfAZw== |
| X-Received | by 2002:a0d:c685:: with SMTP id i127mr20807334ywd.419.1580312742290; Wed, 29 Jan 2020 07:45:42 -0800 (PST) |
| In-Reply-To | <f6382f38-add8-731a-6d47-77d292d013c8@case.edu> |
| X-Mailer | Apple Mail (2.3608.40.2.2.4) |
| X-detected-operating-system | by eggs.gnu.org: Genre and OS details not recognized. |
| X-Received-From | 2607:f8b0:4864:20::c32 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| 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 | <https://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> |
| X-Mailman-Original-Message-ID | <A1A301FD-7C11-4F0F-84D1-299CCF10F8D3@gmail.com> |
| X-Mailman-Original-References | <122693AD-B562-43A5-BE64-58B02C72B6EA@gmail.com> <f6382f38-add8-731a-6d47-77d292d013c8@case.edu> |
| Xref | csiph.com gnu.bash.bug:15841 |
Show key headers only | View raw
> On 2020 Jan 29 , at 10:30 a, Chet Ramey <chet.ramey@case.edu> wrote:
>
> On 1/29/20 10:19 AM, Clint Hepner wrote:
>
>> Bash Version: 5.0
>> Patch Level: 11
>> Release Status: release
>>
>> Description:
>>
>> read seems to incorrectly drop a null field when performing word-splitting and more fields than variables.
>>
>> All the examples below use
>>
>> IFS== read -r n v
>>
>> for some input of the form ``name=var...``
>>
>>
>> The relative bit of the POSIX spec concerns how to set the variables when there are fewer arguments
>> to read than there are fields.
>
> There are exactly two variables and two (split) arguments.
>
> "The shell shall treat each character of the IFS as a delimiter and use the
> delimiters as field terminators to split..."
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
>
>
Ah, OK. So if I have
IFS=, read -r n v <<< "a,b,c,"
there are two variables and 3 split arguments: "a", "b", and "c". Then according to the
specification for read, "a" is assigned to n, and we assign to v as follows:
1. first add the second field "b": v=b
2. then the delimiter following "b": v=b,
3. The remaining fields and their delimiters: first v=b,c then v=b,c,
So the final "," in the value of v isn't separating c and a mythical null field, but
is terminating the final field c.
Then
IFS=, read -r n v <<< "a,b,,"
has fields "a", "b", and "", and again v is assigned "b", ",", "", ",".
Thanks Chet and Greg (for pointing out https://mywiki.wooledge.org/BashPitfalls#pf47)
--
Clint
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: read and inconsistent handling of trailing null field? Clint Hepner <clint.hepner@gmail.com> - 2020-01-29 10:46 -0500
csiph-web