Live data from Hacker News

The useful use of cat

mrmr.io

31–40 of 113 posts

Re: The useful use of cat

#31
post #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.

As others have mentioned, you can put `<` anywhere in the command, including at the very beginning. But, I agree that getting up in arms about this is really dumb.

Re: The useful use of cat

#32
post #7

Using `cat file.txt | ...` has always felt more natural to me, so I still use it. If I need to build a long command I've been using the excellent `up` tool to do it, e.g. `cat file.txt | up` https://github.com/akavel/up

Wow that looks amazing, thanks for telling me about this!

Re: The useful use of cat

#33
cat concatenates files together. I often use it for that. Who cares if "files" is just one file? Using cat regardless keeps things uniform. I like it. People who get funny about it are just trying to be clever. Yes I know there are other ways to do it. But you understood what cat did, otherwise you wouldn't have commented on it.

Re: The useful use of cat

#34

cat concatenates files together. I often use it for that. Who cares if "files" is just one file? Using cat regardless keeps things uniform. I like it. People who get funny about it are just trying to be clever. Yes I know there are other ways to do it. But you understood what cat did, otherwise you wouldn't have commented on it.

literally what cat stands for. conCATenate.

Re: The useful use of cat

#35

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 yo…

If I saw

    
It would give me pause. If I saw

    cat file | grep ...
I would understand it instantly, as would any other Unix user. Therefore the latter is better code.

Re: The useful use of cat

#37

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 yo…

Or you could just use cat

Re: The useful use of cat

#39

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 yo…

If I saw It would give me pause. If I saw cat file | grep ... I would understand it instantly, as would any other Unix user. Therefore the latter is better code.

I don't feel <file is obscure. I've seen shell in that style from coworkers and from open source. Your value judgement against it might just be your experience, rather than something universal.

Re: The useful use of cat

#40
The underlying topic for this is that, most shells treat files/redirections as part of the individual commands and not part of the pipelines. Files should be sometimes treated as commands instead, they plug into the fds of a process the same way as commands do.

`cat x | head` attaches `cat x`'s stdout to `head`'s stdin, `Though I will note that, in a way, bash supports this, as it has a modules system, and one of the pre-existing modules in the source tree is a `cat` replacement, through my lack of understanding of C prevents me from working out if its optimal

https://git.savannah.gnu.org/cgit/bash.git/tree/examples/loa...

Post reply on HN