Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Chet Ramey
On 1/13/25 2:02 PM, Steffen Nurpmeso wrote: Chet Ramey wrote in : |On 1/12/25 6:25 PM, Steffen Nurpmeso wrote: | |> Should be doable for bash in the "no-argument" case, which |> currently works though POSIX requires at least one argument: | |If `read' isn't supplied any variable nam

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Steffen Nurpmeso
Chet Ramey wrote in : |On 1/12/25 6:25 PM, Steffen Nurpmeso wrote: | |> Should be doable for bash in the "no-argument" case, which |> currently works though POSIX requires at least one argument: | |If `read' isn't supplied any variable name arguments, bash assigns the |unmodified line, with

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Chet Ramey
On 1/13/25 12:55 AM, Robert Elz wrote: 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 str

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Chet Ramey
On 1/12/25 8:42 PM, Robert Elz wrote: chet.ra...@case.edu said: | Which basically means that the last variable gets everything else on the | line, including non-whitespace IFS characters. Whitespace IFS characters are included as well, just not leading, or trailing IFS whitespace, any oth

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Chet Ramey
On 1/12/25 6:25 PM, Steffen Nurpmeso wrote: Should be doable for bash in the "no-argument" case, which currently works though POSIX requires at least one argument: If `read' isn't supplied any variable name arguments, bash assigns the unmodified line, without any trailing delimiter, to REPLY.

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Greg Wooledge
On Mon, Jan 13, 2025 at 04:11:46 -0500, Lawrence Velázquez wrote: > What exactly is all of this supposed to demonstrate? mapfile has > the same terminator-not-separator behavior everyone is kvetching > about: > > $ printf 'a:b:c:' | { mapfile -td:; declare -p MAPFILE; } > declare -a M

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Lawrence Velázquez
On Mon, Jan 13, 2025, at 3:03 AM, Félix Hauri wrote: > Re-reading man page and this discussion, I thing either this variable is > wrongly named "IFS", as `S` stand for "separator" Okay. Not like it's going to change. > Btw, the command "mapfile" (readarray) seem more suitable** than "read" for

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread microsuxx
does the output @ https://0x0.st/8-Fv.txt make it into the race by cmd @ https://0x0.st/8-Ft.txt i can be as well fully off the topic excuse me then , and plz lemme know .. On Mon, Jan 13, 2025, 9:03 AM Félix Hauri wrote: > Le Sun, Jan 12, 2025 at 04:10:03PM -0500, Chet Ramey a écrit : > >

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread microsuxx
On Mon, Jan 13, 2025, 4:46 AM Greg Wooledge wrote: > 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 b

Re: 'read' sometimes truncates trailing field delimiter

2025-01-13 Thread Félix Hauri
Le Sun, Jan 12, 2025 at 04:10:03PM -0500, Chet Ramey a écrit : > > This is a simplified version how it works: after you remove leading > and trailing IFS whitespace, you read individual fields from the input > using the characters in IFS as field terminators. > If you get to the last variable a

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{:{:{:,},},},:{:{:,},},},:{:{:,},},}

Re: 'read' sometimes truncates trailing field delimiter

2025-01-11 Thread Greg Wooledge
On Sat, Jan 11, 2025 at 08:54:43 -0600, MacBeth wrote: > 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). https://mywiki.wooledge.org/BashPitfalls#pf47 "It's a feature."

'read' sometimes truncates trailing field delimiter

2025-01-11 Thread MacBeth
Configuration Information [Automatically generated, do not change]: Machine: aarch64 OS: darwin23.4.0 Compiler: clang Compilation CFLAGS: -DSSH_SOURCE_BASHRC -DDEFAULT_LOADABLE_BUILTINS_PATH='/opt/homebrew/Cellar/bash/5.2.37/lib/bash:/usr/local/lib/bash:/usr/lib/$ Machine Type: aarch64-apple-darwin