Useless Cat Elimination Low

Using 'cat' to read a single file and pipe its contents to another command is inefficient and unnecessary. Instead, use input redirection ('<') or provide the filename directly to commands that accept file arguments.

Detector ID
shell/useless-cat-elimination@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Unnecessary use of `cat` to pipe file contents to grep.
3cat log.txt | grep "error"

Compliant example

1
2# Compliant: Directly using grep with file as argument, avoiding unnecessary `cat`.
3grep "error" log.txt