From 3865a5179db81f6d55cb9061ecbb81509e78fe58 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 7 Sep 2020 20:33:08 -0700 Subject: [PATCH] Created SC3026 (markdown) --- SC3026.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SC3026.md diff --git a/SC3026.md b/SC3026.md new file mode 100644 index 0000000..f233570 --- /dev/null +++ b/SC3026.md @@ -0,0 +1,29 @@ +## In POSIX sh, ^ in place of ! in glob bracket expressions is undefined. + +### Problematic code: + +```sh +echo foo-[^0]*.jpg +``` + +### Correct code: + +```sh +echo foo-[!0]*.jpg +``` + +### Rationale: + +`[^c]` is frequently used in most regular expression variants to mean "any character except `c`". This is so pervasive that bash, ksh, dash, and BusyBox ash, all allow it. + +However, strictly speaking, the only range complement syntax guaranteed to be supported across shells is `[!c]`. + +### Exceptions: + +If you only intend to target shells that supports this feature, you can change +the shebang to a shell that guarantees support, or [[ignore]] this warning. +Or just rewrite it to be on the technically correct side. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!