diff --git a/SC1026.md b/SC1026.md new file mode 100644 index 0000000..39575ab --- /dev/null +++ b/SC1026.md @@ -0,0 +1,30 @@ +## If grouping expressions inside [[..]], use ( .. ). + +### Problematic code: + +```sh +[[ [ a || b ] && c ]] +[ [ a -o b ] -a c ]] +``` + +### Correct code: + +```sh +[[ ( a || b ) && c ]] +[ \( a -o b \) -a c ]] # or { [ a ] || [ b ]; } && [ c ] +``` +### Rationale: + +`[ .. ]` should not be used to group subexpressions inside `[[ .. ]]` or `[ .. ]` statements. + +For `[[ .. ]]`, use regular parentheses. + +For `[ .. ]`, either use escaped parentheses, or preferably rewrite the expression into multiple `[ .. ]` joined with `&&`, `||` and `{ ..; }` groups. + +### Exceptions: + +None + +### Related resources: + +* [Bash Pitfalls: `if [ [ a = b ] && [ c = d ] ]; then ...`](https://mywiki.wooledge.org/BashPitfalls#pf11) \ No newline at end of file