Skip to content

Files

Latest commit

 

History

History
27 lines (16 loc) · 782 Bytes

SC2305.md

File metadata and controls

27 lines (16 loc) · 782 Bytes

Pattern: Use of expr with : to match a regex

Issue: -

Description

ShellCheck found an expr command using : to match a regex, but the regex is not quoted and therefore being treated as a glob.

This means that if the problematic code is ever executed in a directory containing a file matching [0-9]*, such as 2021-reports or 12 Angry Men [1957].mkv, it will be replaced be replaced and cause the command to error or incorrectly match.

The regex should be quoted to avoid this, like in the correct example.

Example of incorrect code:

expr "$input" : [0-9]*

Example of correct code:

expr "$input" : "[0-9]*"

Further Reading