3 ms·
From my experience, it will never be so efficient that someone smarter than me doesn't publicly shame me for winning the "useless use of cat" award on a forum w
by digitalsushi 4y ago
From my experience, it will never be so efficient that someone smarter than me doesn't publicly shame me for winning the "useless use of cat" award on a forum where I ask for help.
28 years later and I'm still sore I asked for help as a 15 year old that one time. Very effective way to teach a new user.
- deleted 4y ago[deleted]
- Myrmornis 4y agothat’s a lesson that’s no longer applicable on modern machines I think? —- it often makes sense to start a sequence of piped commands with a cat invocation. One reason is that then the order of sources and sinks in the command syntax matches reality.
- samatman 4y agoI always pipe from cat, as a matter of habit. Reason being: I've probably just catted the file at least once, and it's even likely I catted it right before piping it. So I can extend that command from the history, and if I keep piping (likely) I don't have the weird syntactic stutter at the beginning where `blah < file.txt` | next` puts things out of order. Also, you can't mistype `cat file.txt | blah` and overwrite file.txt accidentally with the output of blah. That's ergonomic.
- gnubison 4y ago‘<file.txt blah’ works just fine.
- fomine3 4y agoIt's preference, like Python list comprehensions vs Ruby method chain.
- rotifer 4y agoI often use cat because when constructing a pipeline I'll do multiple rounds of: head filename | ... Once its working I find it easy to just type C-aM-dcat (i.e. beginning-of-line kill-word cat).
- samatman 4y agoThanks for the reminder (sincerely) but to me this is worse, I would use a shell which doesn't offer this particular form of irregular grammar, I hate it. 100% aesthetic, I shouldn't be able to point a file at my prompt and have it end up streamed into the next word. Just awful, 0/10, do not want.
- gnubison 4y agoFrom another perspective it’s more regular that position doesn’t matter. (This behavior works in all POSIX shells, zsh, rc, etc. But not fish :p)
- kccqzy 4y agoAnother reason I still use "cat" is that I don't want the remaining commands to modify the input file, but I don't want to spend the time to inspect the command line to make sure that is the case. For example I'm pretty sure "grep" won't change the input file but "sed" may depending on the "-i" flag. Using "cat" conveniently bypasses all that thinking because the program only gets stdin from a pipe.
- lilyball 4y agoYou can replace `cat file | cmd` with just `cmd <file` though. `cat` is still useful if you need to concatenate multiple files, but when using it just to feed stdin, actual stdin redirection is better. Even when trying to say something like `echo $(cat foo)`, in Bash you can write `echo $(<foo)`. Though other shells may still require `cat` in this scenario.
- gnubison 4y agoOr <file cmd, to preserve the order.