6 ms·
Is it worth mentioning useless uses of cat in this day and age?
by jgtrosh 8y ago
Is it worth mentioning useless uses of cat in this day and age?
- sametmax 8y agoPlease educate me
- znpy 8y agogrep PasswordAuthentication /etc/SSH/sshd_config
- gsich 8y agoWhich is worse then using cat, from a user perspective. Imagine if you look for something else, you have to point the cursor in the middle, right after grep and before the file. With cat |grep you press Arrow-up and Alt+Backspace and you are right where you want to be, ready to search for something else. In scripts you can save the extra process though.
- jgtrosh 8y agoYou mean ctrl-w or <ESC>bC? ;-) I would find it okay without cat to start the next line with "grep newPattern " and then fetching the previous filename with alt-. (edit: or !$ of course, but alt-. is more practical) -- not saying it's necessarily always better, but knowing your shell better (and/or using a better one) is often a viable alternative to using another construct. Also, than* (sorry)
- gumby 8y agoI just use ^...^... or !gre:... and make my edits that way -- it feels much faster and more intuitive than cursoring around, moving my hand over to the arrow keys etc. The shells were developed on keyboards that didn't have arrow keys and have affordances for them.
- gsich 8y agoSeeing that you need to press enter, the arrow keys are not far away. I doubt the later one.
- gumby 8y agoYou doubt that they keyboards lacked arrow keys? Just look at an ASR-33 (teletype) keyboard or ADM3A. The latter had arrows printed on the hjkl keys but there was no special way to generate “arrow” key presses — those terminals sent 7-bit ASCII characters directly. Look at what # and @ do in cooked mode — THAT goes back to Multics. The teletype was a printing terminal and the ADM3A was a “glass teletype” — essentially a printing terminal too. It’s possinle to write a lot of good code this way
- gsich 8y agoNo. I doubt that many used them to program shells. Bash is from 1989 for example.
- gumby 8y agoI'm not trying to argue; there are not "arrow" characters in the ASCII character set. sh, csh ksh and bash were all developed on ascii terminals. Brian had an Ann Arbor Ambassador which does do 8-bit ASCII but we always had them configured to set the top bit as a "meta" key, so essentially you had 7-bit ascii as well. All these terminals were connected by serial lines to computers (an unusued Vax 750 in the case of the GNU project; that was the machine he developed Bash on -- for the other shells, developed at Bell labs, ksh was also developed also ib a vax while sh and csh were developed on PDP-11s IMHO). You can see the key layouts available back in the days of ASCII terminals here: http://xahlee.info/kbd/vt100_terminal.html http://xahlee.info/kbd/vt100_terminal.html and of course use man ascii. FWIW anyway Brian wouldn't have thought about those keys as the intended use of Readline would have been emacs keystrokes (emacs, or EMACS as it was in those days, had recently been ported to Unix by RMS). Interestingly our 36-bit machines (PDP-10s and lispms) had arrow glyphs on their custom non-ASCII keyboards (KTV and space cadet) but they were for mathematical notation, not cursor movement!
- jlgaddis 8y agoIt's a holdover from the "good ol' days", see http://porkmail.org/era/unix/award.html#cat http://porkmail.org/era/unix/award.html#cat
- sametmax 8y agoDamn it, that "for f in *" loop ! This changes everything !
- pmalynin 8y ago</etc/ssh/sshd_config grep PasswordAuthentication
- sametmax 8y agoI've been taught wrong and I've done it wrong for 15 years O_o Thank you. It reminds me of the idiom of putting "# -- coding: utf-8 --" at the top of Python 2.x files. Which is incredibly useful, but nobody remembers, and googles everytime. This comes from the fact the first famous tutorials on Python where written by emacs users, and this editor recognizes this idiom. But fun fact, the regex matching this line is "^[ \t\v]#.?coding[:=][ \t]*([-_.a-zA-Z0-9]+)" (see https://www.python.org/dev/peps/pep-0263/ https://www.python.org/dev/peps/pep-0263/) and accepts many variations (including a vim format). The simplest variation is the dumb "# coding: utf8", which is not only straightforward and easy to remember, but way less magical for anybody reading the code. Bottom line, if you are stuck in 2.x, use "# coding: utf8".
- gsich 8y agoNo. The alternative is not any better. Besides if you don't know what you are looking for, piping greps after each other is faster to type.
- crypt1d 8y agoit isnt. cat + grep feels a lot more 'natural' to many users and makes 0 performance difference in 99.99% of usecases.
- jacquesm 8y agoI'm pretty fanatical about efficiency, but it's kind of annoying to have to remember where in the argument sequence for a whole bunch of commands the input file goes. Of course once you use the 'cat' trick you then have to remember which comments require '-', '-f -' or something to that effect because whoever programmed them didn't think the primary use case was to work as a filter. Pipes are one of Unix's most useful features and cat somefile | asequenceofusefulcommands is a shorthand that anybody should be able to use.
- iforgotpassword 8y agoAs a compromise you could just do "< infile grep word | awk '{...}' | sort" so you still have the input file first but got rid of cat ;)
- jacquesm 8y agoTyping speed has never been my handicap. To me this seems like just another case of premature optimization, the fact that you are typing in a command is a pretty good indication it is a one-off.
- deleted 8y ago[deleted]
- jacquesm 8y agos/comments/commands/ sorry.