4 ms·
Another 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
by kccqzy 4y ago
Another 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.