r/bash • • 20h ago

help TIL that `local` in bash doesn't scope variables the way I assumed inside pipelines

16 Upvotes

I had a function that built a string in a while-read loop inside a pipeline, and a variable set with `local` inside the loop was coming up empty after the loop finished. Turns out each side of a pipeline runs in a subshell, so no amount of `local` helps — the assignments die with the subshell. I ended up using process substitution (`while read ... done < <(some_command)`) instead, which keeps the loop in the current shell. Cost me an hour of staring at a script that "worked" when I ran the pieces by hand.


r/bash • • 7h ago

What is the main to pick bash over other shells?

10 Upvotes

I have to admit, I keep using bash simply because that's what originally came with my distro and I just got too familiar with it. When I look at other shells, I see features that would've been nice to have, but isn't possible to implement in bash. I've accepted that as a compromise so I can just keep using what I'm most familiar with.

This has me thinking - just familiarity aside, are there other reasons why I might want to stick with bash over the others? If I'm gonna have to justify it, I'm thinking it being an official GNU project is a win.

Other than that, what technical reasons should I appreciate? Perhaps its backwards compatibility with older bash versions is something to admire? What else?