Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on What is cat abuse/useless use of cat?

Parent

What is cat abuse/useless use of cat?

+5
−0

Sometimes I share Unix commands online, and people chastise me for "useless use of cat" (UUOC) or "cat abuse".

My cat is quite comfy and doing very well, thank you.

What are they talking about?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+4
−0

Especially in a pedagogical context, the issue with something like cat /dev/random | head -c 20 versus the more straightforward head -c 20 /dev/random is that it communicates that extra ceremony is necessary. It isn't. Using one program instead of two isn't about saving kilobytes of computer memory; it's about saving human thought.

Different brains are going to work differently, and if yours is ridged such that you need that extra program in there, have a great time with that. But it's simply a fact that the cat is useless in that context—even a program that only accepts input from stdin can be written fooprog </dev/random—and most people in tech culture prefer to remove useless components from their tech.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

</dev/random fooprog (1 comment)
</dev/random fooprog
Canina‭ wrote 8 months ago

You can also put the input file direction first, if that makes the overall command easier for you to parse. So you can write

</dev/random fooprog

instead of

fooprog </dev/random

if you want. The observable effect is the same: fooprog will execute with its standard input set up to read from /dev/random.

It might be different if you are doing redirection to other file descriptors (such as >&n in bash) but in most cases you probably don't need to do that. (Instead of >... 2>&1, which is needed if you're using sh, in bash and compatible shells use &>...; and I have a hard time seeing a use case for redirecting input and output to the same place.)