Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Clint Hepner 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: References: <122693AD-B562-43A5-BE64-58B02C72B6EA@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" 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <122693AD-B562-43A5-BE64-58B02C72B6EA@gmail.com> Xref: csiph.com gnu.bash.bug:15841 > On 2020 Jan 29 , at 10:30 a, Chet Ramey wrote: >=20 > On 1/29/20 10:19 AM, Clint Hepner wrote: >=20 >> Bash Version: 5.0 >> Patch Level: 11 >> Release Status: release >>=20 >> Description: >>=20 >> read seems to incorrectly drop a null field when performing = word-splitting and more fields than variables. >>=20 >> All the examples below use >>=20 >> IFS=3D=3D read -r n v >>=20 >> for some input of the form ``name=3Dvar...`` >>=20 >>=20 >> The relative bit of the POSIX spec concerns how to set the variables = when there are fewer arguments >> to read than there are fields. >=20 > There are exactly two variables and two (split) arguments. >=20 > "The shell shall treat each character of the IFS as a delimiter and = use the > delimiters as field terminators to split..." >=20 > = https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#= tag_18_06_05 >=20 >=20 Ah, OK. So if I have IFS=3D, 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=3Db 2. then the delimiter following "b": v=3Db, 3. The remaining fields and their delimiters: first v=3Db,c then = v=3Db,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=3D, 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) --=20 Clint=