Skip to content
koalaman edited this page Jun 27, 2017 · 1 revision

Can't use =~ in [ ]. Use [[..]] instead.

Problematic code:

[ "$input" =~ DOC[0-9]*\.txt ] && echo "match"

Correct code:

[[ "$input" =~ DOC[0-9]*\.txt ]] && echo "match"

Rationale:

=~ only works in [[ .. ]] tests. It does not work with test or [ in any shell.

If you're targeting POSIX sh, rewrite in terms of case or grep instead.

Exceptions:

None.

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