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)<p>[0] <a href="https://www.man7.org/linux/man-pages/man1/cat.1.html" rel="nofollow">https://www.man7.org/linux/man-pages/man1/cat.1.html</a>
[1] <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/reference/curr...</a>
Shell scripting is one of those places where readability is king, and premature optimization is the devil.<p>Yes, there are multiple ways to get by without cat. Are they as obvious to understand? If not, what are we doing?<p>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.<p>Balance, like most things in life.
Related: <a href="https://github.com/wader/catgolf">https://github.com/wader/catgolf</a> (might not be completely serious)
Related:<p><i>The useful use of cat</i><p><a href="https://news.ycombinator.com/item?id=41894933">https://news.ycombinator.com/item?id=41894933</a>
If I didn't have manpages or the option to google I'd probably just use head or tail after doing 'wc -l' to determine line count.<p>head filename -n `wc -l filename`