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

Google the phrase "useless use of cat".

To some, it's a faux-pas. Personally, I like the aesthetics of cat for my own scripts. It follows the "pipe flowing" idiom better.

There are performance reasons why "useless cat" should be avoided though. So avoid it where performance is important (or when some other hardcore CLI jockey is going to see your code :))



Avoiding “useless cat” on the command line is premature optimization. Sure, don’t do it in a script that is invoked a lot but it shouldn’t be a concern when prototyping a filter pipeline.

  $ cat foo | head -4
  b
  a
  c
  b
  
  $ cat foo | head -4 | sort
  a
  b
  b
  c
  
  $ cat foo | head -4 | sort | uniq -c
  1 a
  2 b
  1 c
  
  $ cat foo | head -4 | sort | uniq -c | sort -k1nr | head -1
  2 b


I understand that people say you can replace

    foo < bar
with

    <bar foo
but I've never been able to get myself to do this.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: