SC3026 raised for ^ used in sed regex pattern
For bugs
- Rule Id (if any, e.g. SC1000): SC3026
- My shellcheck version (
shellcheck --versionor 'online'): online - [x] I tried on shellcheck.net and verified that this is still a problem on the latest commit
- [ ] It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue
- [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#!/bin/sh
echo "foo--12" | sed -E s/[^[:alnum:]]/_/g
Here's what shellcheck currently says:
Line 2 SC3026: In POSIX sh, ^ in place of ! in glob bracket expressions is undefined.
Here's what I wanted or expected to see:
No warning. I believe this is a false positive, because the pattern in question is a regex, not shell pattern. Also, tried to execute the problematic code under dash and it's working fine.
Seems legit. I would probably encapsulate the pattern in quotation marks and thus not trigger the warning.
Hmm, there's no errors raised when using quotes. I'd expect that in this case quotes shouldn't change the behaviour though.
I'd expect that in this case quotes shouldn't change the behaviour though.
Indeed. And that's why I think the report is correct and the problem is probably with the shellcheck internals.