You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use { ..; } instead of (..) to avoid subshell overhead.
Problematic code:
([ "$x" ] || [ "$y" ]) && [ "$z" ]
Correct code:
{ [ "$x" ] || [ "$y" ]; } && [ "$z" ]
Rationale:
You appear to be using (..) to group test commands. This creates a subshell, making it unnecessarily slow. Avoid this by using { ..; } to group.
Be careful to note that unlike (..), this requires both a space after the { and a semicolon before the }.
For example, (cmd), (cmd;) and ( cmd ) are all valid, but {cmd}, {cmd;} and { cmd } are all syntax errors because they lack either or both of the spaces and semicolon. The correct form is { cmd; }
Here's a small benchmark showing that the subshell version is more than 100x slower: