Skip to content

Files

Latest commit

 

History

History
27 lines (16 loc) · 815 Bytes

SC2235.md

File metadata and controls

27 lines (16 loc) · 815 Bytes

Pattern: Use of (..) instead of { ..; }

Issue: -

Description

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; }

Example of incorrect code:

([ "$x" ] || [ "$y" ]) && [ "$z" ]

Example of correct code:

{ [ "$x" ] || [ "$y" ]; } && [ "$z" ]

Further Reading