=~
is for regex, but this looks like a glob. Use =
instead.[[ $file =~ *.txt ]]
[[ $file = *.txt ]]
You are using =~
to match against a regex --
specifically a Extended Regular Expression (ERE) -- but the right-hand
side looks more like a glob:
*
, like in *.txt
.txt
, like
readme.txt
but not foo.sh
txt
, such as *itxt
but not
test.txt
*
, like in
s*
.
s
, such
as shell
and set
.s
s, such as
dog
(because it does in fact contain zero or more
s
's)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.
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.