Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
SC2002: when cat is on a line on its own, suggest putting the redirection before the command instead #1640
Here's a snippet or screenshot that shows the problem:
#!/bin/sh cat file | tr '[:cntrl:]' '?' | sort | uniq -c
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
Having the filename first is more aesthetically pleasing, especially with multi-line pipelines, which is why many people use cat, but they don't know about "< file cmd" redirections so then end up with useless-use-of-cat.
I'm not sure about the multi-line suggestion, but I think a quoted string would be more confusing due to the line continuation character and then escaped newline: "< file \ncmd".
The rule's wiki page does put the filename before the command in one case, but doesn't have a multi-line case and the suggestions ShellCheck produces for SC2002 should reflect the multi-line case.
I found some discussion about this on StackOverflow.