Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Robert Elz
Date:Sun, 12 Jan 2025 22:39:57 -0500 From:Greg Wooledge Message-ID: <20250113033957.gc27...@wooledge.org> | At the risk of going a bit off topic, may I ask *why* the shell does | that? Were there any files or data stream conventions in common use | in the 1970s

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Greg Wooledge
On Mon, Jan 13, 2025 at 08:42:39 +0700, Robert Elz wrote: > It is unexpected, because users believe (from other experience) > that the delimiters separate fields, but in sh they don't, they > terminate fields. At the risk of going a bit off topic, may I ask *why* the shell does that? Were there a

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Robert Elz
Date:Sun, 12 Jan 2025 16:55:05 -0500 From:Greg Wooledge Message-ID: <20250112215505.gb27...@wooledge.org> | Right. You explained why it works the way it does. But from a user's | point of view, it's just unexpected behavior. It is unexpected, because users beli

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Steffen Nurpmeso
Greg Wooledge wrote in <20250112215505.gb27...@wooledge.org>: |On Sun, Jan 12, 2025 at 16:26:04 -0500, Chet Ramey wrote: |>> In this case, we get the "expected" result: |> |> You just restated the original example while ignoring the part of my |> message about looking for additional input af

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Chet Ramey
On 1/12/25 4:55 PM, Greg Wooledge wrote: On Sun, Jan 12, 2025 at 16:26:04 -0500, Chet Ramey wrote: In this case, we get the "expected" result: You just restated the original example while ignoring the part of my message about looking for additional input after you find a delimiter. Right. Y

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Greg Wooledge
On Sun, Jan 12, 2025 at 16:26:04 -0500, Chet Ramey wrote: > > In this case, we get the "expected" result: > > You just restated the original example while ignoring the part of my > message about looking for additional input after you find a delimiter. Right. You explained why it works the way it

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Chet Ramey
On 1/12/25 4:19 PM, Greg Wooledge wrote: On Sun, Jan 12, 2025 at 16:10:03 -0500, Chet Ramey wrote: This is a combination of two rules: characters in IFS are field terminators, not separators, and when `read' is supplied fewer variables than fields, "Any remaining input in the original field bei

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Lawrence Velázquez
On Sun, Jan 12, 2025, at 10:19 AM, MacBeth wrote: > On Sun, Jan 12, 2025 at 8:58 AM MacBeth wrote: > >> And here is a version you would have to use without `sed` to get the line >> first, before you can append the field terminator to it: >> >> delim=, >> { >> while IFS= read -r row; do >>

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Greg Wooledge
On Sun, Jan 12, 2025 at 16:10:03 -0500, Chet Ramey wrote: > This is a combination of two rules: characters in IFS are field > terminators, not separators, and when `read' is supplied fewer > variables than fields, > > "Any remaining input in the original field being processed shall be > returned t

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Chet Ramey
On 1/11/25 9:54 AM, MacBeth wrote: Bash Version: 5.2 Patch Level: 37 Release Status: release Description: It seems that `read` truncates a trailing delimiter if there is one less variable argument than input fields and the last field is empty (trailing delimiter). This is a combination of tw

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread MacBeth
On Sun, Jan 12, 2025 at 8:58 AM MacBeth wrote: > On Sun, Jan 12, 2025 at 8:24 AM Félix Hauri wrote: > >> Le Sat, Jan 11, 2025 at 10:49:50AM -0500, Greg Wooledge a écrit : >> > https://mywiki.wooledge.org/BashPitfalls#pf47 >> > "It's a feature." >> > >> -- how do we work around this nonsense? >>

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread MacBeth
On Sun, Jan 12, 2025 at 8:24 AM Félix Hauri wrote: > Le Sat, Jan 11, 2025 at 10:49:50AM -0500, Greg Wooledge a écrit : > > https://mywiki.wooledge.org/BashPitfalls#pf47 > > "It's a feature." > > > -- how do we work around this nonsense? > > I've alredy noticed this, but never stictly tested them

Re: 'read' sometimes truncates trailing field delimiter

2025-01-12 Thread Félix Hauri
Le Sat, Jan 11, 2025 at 10:49:50AM -0500, Greg Wooledge a écrit : > https://mywiki.wooledge.org/BashPitfalls#pf47 > "It's a feature." > -- how do we work around this nonsense? I've alredy noticed this, but never stictly tested them as: for row in k{:v1{:v2{:{:{:,},},},:{:{:,},},},:{:{:,},},}