Skip to content

feature request: detect wrong placement of /dev/null redirection #3078

@Villemoes

Description

@Villemoes

For bugs

For new checks and feature suggestions

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

I managed to write something like this

#!/bin/sh
rmdir "/foo/bar" || true 2> /dev/null 

and only spotted the problem myself after the code was merged.

Here's what shellcheck currently says:

Nothing.

Here's what I wanted or expected to see:

Some warning about the /dev/null silencing being applied to a command that will never emit anything, and given the || true, was likely meant to be applied to the LHS command. So this is probably two feature requests (or easiest to do if considered like that): Output redirections applied to builtins like true, false, : are most likely useless, at least when the destination is also a known subject like /dev/null (true > file is not useless). And when a command is followed by || true , it is likely that any redirection of output applied to the RHS was meant to apply to the LHS.

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