--pattern
- Accepted by
opengrep scan- Also spelled
-e- Value
PATTERN- See also
--lang,--replacement,--config,patterns,pattern
Searches with one pattern, without a rule file, to find code by its structure rather than by its text. The pattern uses the pattern syntax of a rule: eval(...) matches any call to eval.
-e and -l/--lang must be given together, since the pattern is parsed as code of a language. Without -l, Opengrep stops with -e/--pattern and -l/--lang must both be specified and exit status 2.
A finding of a command-line pattern has no rule: it is reported with - as its rule id, the pattern as its message, and the severity ERROR. The text output shows only the matched lines. --replacement adds a fix to the pattern.
Examples
Searching for a call
app.py
eval(1)print(2)Command and result
$ opengrep scan -q -e 'eval(...)' -l python app.py
app.py
1: eval(1)
$ opengrep scan -e 'eval(...)' app.py 2>&1 >/dev/null | tail -1
[00.00][ERROR]: -e/--pattern and -l/--lang must both be specified