The main purpose of `cat` is not to print a single file to stdout but to conCATenate files to stdout [0].
Of course if I have a single file it's printed alone.
Just here to say that `cat` is not a synonym of `print`, but nowadays it's "cat FILE" everywhere. Even in APIs... [1] (Compact and aligned text? XD)
pagers are sometimes more of a burden than a help. If a file is relatively short, the terminal's scrollback may be sufficient to navigate the content. A pager may not cooperate well with the terminal's UI for scrolling, and may even mess up scrollback history. And, depending on configuration, may clear the screen when it's closed against the user's wishes.
Yes, there may be flags you can throw on them to make them behave the way you want, but those flags need to be remembered. `cat` is certainly shorter to type and easier to remember than `less -X`
Shell scripting is one of those places where readability is king, and premature optimization is the devil.
Yes, there are multiple ways to get by without cat. Are they as obvious to understand? If not, what are we doing?
Shell scripting isn't meant for performance but composability. If you're fighting me over micro optimizations, I'm just going to rewrite it in a proper language and 100x its performance. But then it's lost its readability and it's no longer editable.
At a certain point, it's not a problem with readability but that the reader doesn't actually know the language.
Is it a readability problem if someone is confused about foreach loops in Java, or perhaps we should expect the person to actually learn the language they are using?
Input redirection is a fundamental shell language feature.
In most cases you could simply use a huge number of lines like
head filename -n 1000000000
or use the "inverse mode". Head and tail can print all but the first/last n lines (I just have trouble to remember without man page the syntax and which does what).
So those are more "cat equivalents":
head -n-0 filename
tail -n+0 filename
PS: for your wc example you could actually do just
head -n $(wc -l filename)
because `wc` will print the number of lines and the filename. (does not work with spaces)
[0] https://www.man7.org/linux/man-pages/man1/cat.1.html [1] https://www.elastic.co/guide/en/elasticsearch/reference/curr...