---
title: Avoid cat when it only forwards one file to the next command
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid cat when it only forwards one file to the next command
---

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

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `bash-code-quality/useless-cat`

**Language:** Bash

**Severity:** Notice

**Category:** Code Style

## Description{% #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{% #non-compliant-code-examples %}

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

## Compliant Code Examples{% #compliant-code-examples %}

```bash
#!/bin/bash
grep pat file.txt
cat file.txt
cat a b | wc
cat -n file.txt | head
cat - | wc
cat -- file | wc
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 