shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC3026 raised for ^ used in sed regex pattern

Open serpent7776 opened this issue 5 months ago • 3 comments

For bugs

  • Rule Id (if any, e.g. SC1000): SC3026
  • My shellcheck version (shellcheck --version or '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.

serpent7776 avatar Jul 31 '25 19:07 serpent7776

Seems legit. I would probably encapsulate the pattern in quotation marks and thus not trigger the warning.

brother avatar Aug 05 '25 08:08 brother

Hmm, there's no errors raised when using quotes. I'd expect that in this case quotes shouldn't change the behaviour though.

serpent7776 avatar Aug 06 '25 19:08 serpent7776

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.

brother avatar Aug 07 '25 08:08 brother