Skip to content

Files

Latest commit

 

History

History
33 lines (19 loc) · 798 Bytes

SC2022.md

File metadata and controls

33 lines (19 loc) · 798 Bytes

Pattern: Possible regular expression misuse in shell script

Issue: -

Description

As a glob, foo* means "Any string starting with foo", e.g. food and foosball.

As a regular expression, "foo*" means "f followed by 1 or more o's, anywhere", e.g. "mofo" or "keyfob".

This construct is way more common as a glob than as a regex, so ShellCheck notifies you about it.

Example of incorrect code:

grep 'foo*'

when wanting to match food and foosball, but not mofo or keyfob.

Example of correct code:

grep '^foo'

Exceptions

If you're aware of the above, you can ignore this message. If you'd like shellcheck to be quiet, use a directive or 'fo[o]*'.

Further Reading