=~regex matching is undefined.
[ "$var" =~ .*foo[0-9]* ]
expr "$var" : ".*foo[0-9]*" > /dev/null
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.
: operator instead.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.