Skip to content

bash: cat in variable assignment -> redirect? #2493

@sburris0

Description

@sburris0

For new checks and feature suggestions

While reading through the bash manual I encountered this:

The command substitution $(cat file) can be replaced by the equivalent but faster $(< file). 

It's a relatively minor thing but it might be worth suggesting to users.
Thoughts?

Here's a snippet or screenshot that shows the problem:

#!/bin/bash
var=$(cat file.txt)

Here's what shellcheck currently says:

n/a

Here's what I wanted or expected to see:

Suggestion to use var=$(< file.txt) instead

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions