Skip to content

Files

Latest commit

 

History

History
25 lines (15 loc) · 500 Bytes

SC2074.md

File metadata and controls

25 lines (15 loc) · 500 Bytes

Pattern: Use of =~ in [ ]

Issue: -

Description

=~ 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.

Example of incorrect code:

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

Example of correct code:

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

Further Reading