mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Created SC1028 (markdown)
31
SC1028.md
Normal file
31
SC1028.md
Normal file
@@ -0,0 +1,31 @@
|
||||
## In [..] you have to escape \\( \\) or preferably combine [..] expressions.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
[ -e ~/.bashrc -a ( -x /bin/dash -o -x /bin/ash ) ]
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
In POSIX:
|
||||
```sh
|
||||
[ -e ~/.bashrc ] && { [ -x /bin/dash ] || [ -x /bin/ash ]; }
|
||||
```
|
||||
|
||||
Obsolete XSI syntax:
|
||||
```sh
|
||||
[ -e ~/.bashrc -a \( -x /bin/dash -o -x /bin/ash \) ]
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
`[` is implemented as a regular command, so `(` is not special.
|
||||
|
||||
The preferred way is not to group inside `[ .. ]` and instead compose multiple `[ .. ]` statments 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.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None
|
Reference in New Issue
Block a user