From a3f0489729afd6588d02d2c53ed240aa3f94cdfd Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 3 Jun 2017 11:40:16 -0700 Subject: [PATCH] Created SC1028 (markdown) --- SC1028.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 SC1028.md diff --git a/SC1028.md b/SC1028.md new file mode 100644 index 0000000..b2e87b2 --- /dev/null +++ b/SC1028.md @@ -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 \ No newline at end of file