Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "shopt -s lastpipe" efficient?

Tags:

bash

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?

like image 416
mickp Avatar asked Sep 06 '25 17:09

mickp


1 Answers

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.

like image 97
Charles Duffy Avatar answered Sep 10 '25 02:09

Charles Duffy