For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/bash-code-quality/useless-cat.md. A documentation index is available at /llms.txt.

Avoid cat when it only forwards one file to the next command

This product is not supported for your selected Datadog site. ().

Metadata

ID: bash-code-quality/useless-cat

Language: Bash

Severity: Notice

Category: Code Style

Description

When cat reads one path and its output is piped to another command, the cat step is usually redundant. Pass the file path to that command or use shell redirection instead.

Non-Compliant Code Examples

#!/bin/bash
cat file.txt | grep pat
cat ./x | wc -l
/bin/cat foo | head

Compliant Code Examples

#!/bin/bash
grep pat file.txt
cat file.txt
cat a b | wc
cat -n file.txt | head
cat - | wc
cat -- file | wc
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security