4 ms·
Like a lot of people, he overuses cat when it's not needed. `cat FOO | more` is approximately equivalent to `more < FOO`, except the first one spawns an extra p
by mtdewcmu 11y ago
Like a lot of people, he overuses cat when it's not needed. `cat FOO | more` is approximately equivalent to `more < FOO`, except the first one spawns an extra process for no reason.
- throwaway999888 11y ago> except the first one spawns an extra process for no reason. I wonder how many processes I could spin up in the time it would take for me to figure out "hmm, no, invoking that command would use one more process than necessary..." I don't give a hoot about that stuff when I'm doing stuff interactively. e.g. when using `more`.
- deleted 11y ago[deleted]
- throwaway999888 11y agoBTW, the authors effectively embraced having the functionality of using `cat` instead of < . > The use of cat to feed a single input file to a program has to some degree superseded the shell’s < operator, which illustrates that general-purpose constructs - like cat and pipes - are often more natural than convenient special-purpose ones.
- mtdewcmu 11y agoIf you're going to write shell scripts or do anything sophisticated with the shell, it's worth understanding the difference. And there is a fundamental difference. With |, standard input is hooked up to a pipe. With <, standard input is hooked up directly to the file. Sometimes it does matter.
- isolate 11y agoThe purpose cat serves is that it lets you forget about < until you really need it.
- throwaway999888 11y agoThe comparison was between cat + pipe and < ...
- hawski 11y agoIn my opinion it's better to replace `cat FOO | more` with `< FOO more`, because cat is used because people first think that they want to take contents of some file and pass it through some filter.
- mtdewcmu 11y agoI didn't know you could put the redirection first. You learn something new every day. Maybe that form would make it more mnemonic for some people, because it more resembles a pipeline.