Re:Something about functions in Bash (2017)
by llimllib on Thursday July 05, 2018 @03:08PM
(#17465896)
If you rely on `(` instead of `{` to create a subshell and you don't comment the heck out of it, you are doing evil
[ Parent
| on HN ]
Re:Something about functions in Bash (2017)
by ben509 on Thursday July 05, 2018 @07:00PM
(#17467597)
Even more fun: I was working on an unholy bash script that had a long curly brace block, and I was wondering why none of the environment variables survived.
Then I noticed, tucked away at the end:
...
kill --all humans
touch $children
fork yourself
} | log
Because, you see, components of a pipeline have to be run in subshells...I was about to comment about how it took me several reads and then finally reading the "compound commands" section of `BASH(1)` to recognize the use of `(` vs `{` in the examples. That distinction should have been made clear in the example IMO.
Re:Something about functions in Bash (2017)
by yjftsjthsd-h on Thursday July 05, 2018 @08:51PM
(#17468120)
Why? () is the obvious way to get an independent subshell. I guess it's annoying if you're not used to the distinction, but it's not hard. Is it really not common knowledge?
Re:Something about functions in Bash (2017)
by llimllib on Friday July 06, 2018 @04:27PM
(#17474850)
Because it parses, visually, EXTREMELY similarly to `{` in a place where almost everybody who programs in a brace-y language will expect a brace.
Thus most people will not notice it unless you point it out very explicitly, and it has the potential to cause great confusion.