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

Metadata

ID: bash-code-quality/avoid-ls-grep-pipelines

Language: Bash

Severity: Notice

Category: Code Style

Description

Parsing ls output is fragile (locale, columns, odd filenames). Piping ls to grep is a common anti-pattern. Prefer shell globs, find, or tools that work on paths instead of ls text.

Non-Compliant Code Examples

#!/bin/bash
ls | grep foo
ls -la | grep '\.txt$'
ls |& grep foo

Compliant Code Examples

#!/bin/bash
ls
printf '%s\n' *.txt
find . -maxdepth 1 -name '*.log' -print
ls | something | grep
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