$ 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.
Both cases should trigger SC2002 based on the above context. Unless the rationale for the second case is similar to:
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.