Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's a perfectly valid pet peeve, especially with things like `tr` being weird about accepting files as input.

This works:

  cat file.log | tr 'a' 'b'
This doesn't:

  tr 'a' 'b' file.log


   tr a b < file.log

   < file.log tr a b

The pattern "cat file | command" introduces an unnecessary cat process to achieve the effect of "< file command".

It is not called "useless use of cat" (UUoC) without justification.


It is not called "useless UUoC comment" (UUUoCC) without justification. ;)

From a personal taste perspective, I'm not a fan of either. Having a floating "<" at the start of a line just isn't my cup of tee. Not dealing with explicit stdin/stdout just makes my code easier to read. And especially considering the post's advice is about reading logs, a lot of the post is very likely built around outage resolution. Not the time I want to be thinking "oh yeah `tr` is special and I need to be explicit" -- nah, just use cat as a practice. And no, I'm not going to write `grep blah < filename` as a practice just because of commands like `tr` being weird.

But honestly, if it's such a big deal to have a cat process floating around, there are probably other things you should be concerned about. "Adds extra load to the server" points to other problems. If perf matters, CPU shielding should be used. Or if that's not an option, then sure, there's some room for trifling around, but if you're at a point where you're already running a series of pipes, a single cat command is beans compared to the greps and seds that come after it.




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

Search: