SC2049 – ShellCheck Wiki

See this page on GitHub

Sitemap


=~ is for regex, but this looks like a glob. Use = instead.

Problematic code:

[[ $file =~ *.txt ]]

Correct code:

[[ $file = *.txt ]]

Rationale:

You are using =~ to match against a regex -- specifically a Extended Regular Expression (ERE) -- but the right-hand side looks more like a glob:

Please ensure that the pattern is correct as an ERE, or switch to glob matching if that's what you intended.

This is similar to SC2063, where grep "*foo*" produces an equivalent warning.

Exceptions:

If you are aware of the difference, you can ignore this message, but this warning is not emitted for the more probable EREs \*.txt, \.txt$, ^s or s+, so it should rarely be necessary.


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.