From 091fd0244ad78da9e4ae1ef87361d4ecc41bf3c7 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 17 Aug 2021 22:08:13 -0700 Subject: [PATCH] Created SC3015 (markdown) --- SC3015.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SC3015.md diff --git a/SC3015.md b/SC3015.md new file mode 100644 index 0000000..c80d304 --- /dev/null +++ b/SC3015.md @@ -0,0 +1,29 @@ +## In POSIX sh, =~ regex matching is undefined. + +### Problematic code: + +```sh +[ "$var" =~ .*foo[0-9]* ] +``` + +### Correct code: + +```sh +expr "$var" : ".*foo[0-9]*" > /dev/null +``` + +### Rationale: + +You are using `=~` in a script declared to be compatible with POSIX sh or Dash. + +`=~` is not a POSIX operator and is unlikely to outside `[[ ]]` in Bash and Ksh. + +Use `expr`'s `:` operator instead. + +### Exceptions: + +None + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file