Live data from Hacker News

The useful use of cat

mrmr.io

21–30 of 113 posts

Re: The useful use of cat

#24
post #16

Earlier quoted context omitted.

Whether there are formal examples or not, the thing you're doing during REPL driven programming is testing . It's just rapid, iterative and informal.

TDD refers to a specific kind of testing methodology, not just any and all testing. Manual testing is not TDD.

[deleted]

Re: The useful use of cat

#25
People who get up in arms about "useless" uses of cat need to chill out. I read my pipelines left to right. Using a 'after the command means I have to swap my reading direction back and forth, and why bother with that? I have better things to do with my brain energy.

Re: The useful use of cat

#26

You can still just begin with <somefile instead of cat somefile |. Does it really matter? No, but I don’t think pointing out useful and concise built-ins is necessarily asinine.

Can you? In bash I end up with no input at all if I start the line with '<somefile'.

Re: The useful use of cat

#27
if you prefer to use cat just to read your pipeline from left to right, you can just start your command with file redirection. It doesn't have to be at the end of the command.

  
this works in bash too, but if you're using zsh, there're a couple of nice shortcuts

  
on it's own works as

  more file
and

  > file
  ...
  ...
  ^D
allows you to put something into the file quickly without firing up the editor. Though

  > file 
will give you nicer line editing experience.

more zsh redirection tricks here: https://zsh.sourceforge.io/Doc/Release/Redirection.html#Mult...

Re: The useful use of cat

#28
post #9

Does anyone take the "don't use cat" stuff seriously?

It's more of a symptom of someone who doesn't understand what's actually going on, i.e. cargo cult scripting.

Specifically, it indicates some combination of:

1. isn't aware of processes/pipes

2. isn't aware of cat's "primary" functionality

3. isn't aware of shell input redirection

4. isn't aware that shell input redirection can be put before the command

Re: The useful use of cat

#30

My main use of cat is for clipboard pasting (if I can't leverage pbpaste or something more appropriate). If I want to get something into a file or get into a pipe as stdin `cat > file` or `cat | cmd`, paste, then end with cmd-D to send an EOF and terminate the cat. For files it circumvents "helpful" formatting you would get pasting into an editor.

if you're on os x, you can also do

  pbpaste > file
and if you're using zsh, just

  > file
is sufficient, without cat
Post reply on HN