SC3015 – ShellCheck Wiki

See this page on GitHub

Sitemap


In POSIX sh, =~ regex matching is undefined.

Problematic code:

[ "$var" =~ .*foo[0-9]* ]

Correct code:

expr "$var" : ".*foo[0-9]*" > /dev/null

Rationale:

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.

Use expr's : operator instead.

Exceptions:

None


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