TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Cat without cat on the commandline (2020)

25 pointsby zoidb7 months ago

8 comments

basemi7 months ago
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&#x27;s printed alone. Just here to say that `cat` is not a synonym of `print`, but nowadays it&#x27;s &quot;cat FILE&quot; everywhere. Even in APIs... [1] (Compact and aligned text? XD)<p>[0] <a href="https:&#x2F;&#x2F;www.man7.org&#x2F;linux&#x2F;man-pages&#x2F;man1&#x2F;cat.1.html" rel="nofollow">https:&#x2F;&#x2F;www.man7.org&#x2F;linux&#x2F;man-pages&#x2F;man1&#x2F;cat.1.html</a> [1] <a href="https:&#x2F;&#x2F;www.elastic.co&#x2F;guide&#x2F;en&#x2F;elasticsearch&#x2F;reference&#x2F;current&#x2F;cat.html" rel="nofollow">https:&#x2F;&#x2F;www.elastic.co&#x2F;guide&#x2F;en&#x2F;elasticsearch&#x2F;reference&#x2F;curr...</a>
评论 #41901783 未加载
silisili7 months ago
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&#x27;t meant for performance but composability. If you&#x27;re fighting me over micro optimizations, I&#x27;m just going to rewrite it in a proper language and 100x its performance. But then it&#x27;s lost its readability and it&#x27;s no longer editable.<p>Balance, like most things in life.
评论 #41909061 未加载
jwilk7 months ago
Related: <a href="https:&#x2F;&#x2F;github.com&#x2F;wader&#x2F;catgolf">https:&#x2F;&#x2F;github.com&#x2F;wader&#x2F;catgolf</a> (might not be completely serious)
ilyagr7 months ago
Took me a bit to figure out a nice way to do this in the `fish` shell. I think it&#x27;s `string collect &lt; file.txt`.
ChrisArchitect7 months ago
Related:<p><i>The useful use of cat</i><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41894933">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41894933</a>
vman817 months ago
If I didn&#x27;t have manpages or the option to google I&#x27;d probably just use head or tail after doing &#x27;wc -l&#x27; to determine line count.<p>head filename -n `wc -l filename`
评论 #41901977 未加载
optymizer7 months ago
On what kind of Linux system do you get a shell but don&#x27;t have access to `cat`?
评论 #41901553 未加载
评论 #41901641 未加载
its-summertime7 months ago
the read&#x2F;echo loop will not handle nulls<p>the command substitution will mangle ending newlines