Skip to content
Joachim Ansorg edited this page Nov 15, 2021 · 2 revisions

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally

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

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!