5 ms·
> Just use cat. We’ve gone full circle. https://en.m.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat https://en.m.wikipedia.org/wiki/Cat_(Unix)#Useless_use_o
by jhardy54 4y ago
> Just use cat.
We’ve gone full circle.
https://en.m.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat https://en.m.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_ca...
- nikau 4y agoThe reason to use cat is so you don't risk accidentally overwriting the source file by messing up a command. Anything after the "cat file |" can't overwrite the file.
- jhugo 4y agoThat seems like a bad reason. You can always overwrite the file by messing up the command. cat file | cat > file (This won't, as you might hope, leave the file unchanged.) Re-read what you typed before hitting enter, and keep backups of important things.
- nikau 4y agoThat's an unlikely mistake. More likely is you are messing around with some new/infrequently used utility and you pass in the arguments incorrectly and specify "file" as the output instead of the input as intended.
- jhugo 4y agoThe one I typed is unlikely (I wrote it in response to your "Anything after the `cat file |` can't overwrite the file", which is factually incorrect as demonstrated), but there are plenty of other simple mistakes. Understand what you're running, and keep backups, otherwise you'll screw up eventually. Selecting your tools this way doesn't move the needle much.
- nikau 4y agoRemoving cat and specifying the file directly to the utility doesn't move the needle in any tangible way either. At the end of the day do whatever pattern works for you - for me it's doing "cat file |" at the start of a pipeline and "> outfile" at the end. I also avoid globbing inside a pipeline as it can be dangerous too.
- yakubin 4y agoYou can replace "cat file |" with "<file".
- jhugo 4y agoWell, yes, but then it wouldn't have been a very good demonstration of why the statement "anything after the `cat file |` can't overwrite the file" is incorrect.