Skip to content

Files

Latest commit

 

History

History
33 lines (21 loc) · 816 Bytes

SC1028.md

File metadata and controls

33 lines (21 loc) · 816 Bytes

Pattern: Unescaped ( or ) in [..]

Issue: -

Description

[ is implemented as a regular command, so ( is not special.

The preferred way is not to group inside [ .. ] and instead compose multiple [ .. ] statements using the shell's &&, || and { ..; } syntax, since this is well defined by POSIX.

Some shells, such as Bash, support grouping with \( .. \), but this is an obsolete XSI-only extension.

Example of incorrect code:

[ -e ~/.bashrc -a ( -x /bin/dash -o -x /bin/ash ) ]

Example of correct code:

In POSIX:

[ -e ~/.bashrc ] &&  { [ -x /bin/dash ] || [ -x /bin/ash ]; }

Obsolete XSI syntax:

[ -e ~/.bashrc -a \( -x /bin/dash -o -x /bin/ash \) ]

Further Reading