Does anyone take the "don't use cat" stuff seriously?
It's more of a symptom of someone who doesn't understand what's actually going on, i.e. cargo cult scripting. Specifically, it indicates some combination of: 1. isn't aware of processes/pipes 2. isn't aware of cat's "primary" functionality 3. isn't aware of shell input redirection 4. isn't aware that shell input redirection can be put before the command
The useful use of cat
51–60 of 113 posts
Re: The useful use of cat
#52Earlier quoted context omitted.
When you want to tail a file, but you want it in descending order and you’re not sure how much of it you want: tac file | less
I guess the difference is that I expect things to read top to bottom, so I'd do that as less foo.log G
Re: The useful use of cat
#53Re: The useful use of cat
#54The 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 th…
Is it as optimal as just attaching the file descriptor? No, because you will have to pipe the contents. Is it optimal (or at least optimal enough)? Considering how pipes work, yes.
Re: The useful use of cat
#55Re: The useful use of cat
#56if 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
#57cat | sudo tee somefile > /dev/null is still my favorite way to paste text into an ssh session and save it to a protected file.
file'
And you could just use scp, but I've found clients without scp and servers with the SFTP subsystem disabled.Re: The useful use of cat
#58Earlier quoted context omitted.
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.
Furthermore, a little memory lapse or typo, and, oops! >byebyefile
Re: The useful use of cat
#59Re: The useful use of cat
#60Earlier quoted context omitted.
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.