Hacker News new | past | comments | ask | show | jobs | submit login

Why always start with cat? Not using cat when you don’t need to means less typing, more efficient and mor robust code. Why use it if you don’t need to?



It's easier to change the start of a chain that starts with cat than if you're passing a filename into your first program. Even though it's _technically_ misuse, cat can improve composability.


I often prefer it in scripts for easier parsing later.

cat file.txt | somemonstrousoneliner

immediately tells me it's reading file.txt and doing something with the contents.

Burying the filename deeper in the string makes it harder to figure that out.


In many situations it's quicker to just rely on muscle memory than coming up with the most efficient way to read a few 50kB files.

It's a good thing to be aware of the differences when needed, but often the execution speed is not the reason for writing a bash script.


I don’t think efficiency matters much in this case, but more robust and concise code is better. Most commands either take a file as a unnamed argument or you can just do something like <filename. But I agree, there may be commands where passing the file name is awkward (eg. jq)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: