Re: Scope change in loops with "read" built-in

2024-04-05 Thread Greg Wooledge
On Thu, Apr 04, 2024 at 08:39:51PM -0400, Dale R. Worley wrote: > To circumvent that, I've sometimes done things like > > exec 3<( ... command to generate stuff ... ) > while read VAR <&3; do ... commands to process stuff ... ; done > exec 3<- Please note that the syntax for closing a

Re: Scope change in loops with "read" built-in

2024-04-05 Thread Kerin Millar
On Thu, 04 Apr 2024 20:39:51 -0400 "Dale R. Worley" wrote: > "Linde, Evan" writes: > > In a loop constructed like `... | while read ...`, changes to > > variables declared outside the loop only have a loop local > > scope, unlike other "while" or "for" loops. > > Yeah, that's a gotcha. But it

Re: Scope change in loops with "read" built-in

2024-04-04 Thread Dale R. Worley
"Linde, Evan" writes: > In a loop constructed like `... | while read ...`, changes to > variables declared outside the loop only have a loop local > scope, unlike other "while" or "for" loops. Yeah, that's a gotcha. But it's a general feature of *pipelines*, documented in Each command i

RE: Scope change in loops with "read" built-in

2024-04-02 Thread Linde, Evan
Greg, thank you -- this was exactly what I've been failing to find. And there's even a solution that looks good for my *actual* problem. -Original Message- From: Greg Wooledge Sent: Tuesday, April 2, 2024 3:35 PM To: Linde, Evan Cc: bug-bash@gnu.org Subject: Re: Scope chang

Re: Scope change in loops with "read" built-in

2024-04-02 Thread Greg Wooledge
On Tue, Apr 02, 2024 at 08:08:57PM +, Linde, Evan wrote: > In a loop constructed like `... | while read ...`, changes to > variables declared outside the loop only have a loop local > scope, unlike other "while" or "for" loops. https://mywiki.wooledge.org/BashFAQ/024