Skip to content

Potentially Inconsistent detection of useless-use-of-cat #3458

@mikeBashStuff

Description

@mikeBashStuff
  • version: 0.11.0
  • SC2002
$ echo 'f=kaka; cat "$f" | grep .' |  shellcheck -fgcc -sbash  --enable=useless-use-of-cat -
-:1:13: note: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. [SC2002]
$ echo 'f=kaka; cat $f | grep .' |  shellcheck -fgcc -sbash  --enable=useless-use-of-cat -
$

Both cases should trigger SC2002 based on the above context. Unless the rationale for the second case is similar to:

$ echo 'f=(kaka puss); cat "${f[@]}" | grep .' |  shellcheck -fgcc -sbash  --enable=useless-use-of-cat -
$ echo 'f="kaka puss"; cat $f | grep .' |  shellcheck -fgcc -sbash  --enable=useless-use-of-cat -
# This raises SC2086 which is expected, proves though that shellcheck understands the context of $f

Where cating multiple files doesn't really fall under UUOC. That said, shellcheck should already have a proper context for the seconds case, realizing potential read from a single file.

Probably not a bug, rather severe case of nitpicking; food for thought.

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