There are recommendations all over the place to avoid unnecessary subshells. It makes me wonder whether it is efficient to generally have the lastpipe
option enabled so that the last command in a pipeline is not executed in a subshell?
More efficient? Sure.
Best-practice? That depends on what you prioritize.
If you care about consistent behavior between interactive and noninteractive shells, shopt -s lastpipe
on bash has substantial tradeoffs, because it has no effect when job control is enabled. Thus, scripts which depend (either intentionally or implicitly) on the last piece of a pipeline running in the same process can silently fail if that code is transported to a context where the lastpipe flag is either unset or ineffective on account of implementation constraints.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With