5 ms·
I build pipes left to right, and I read pipes left to right... 1 -> 2 -> 3 is easier that (2 <- 1) -> 3
by vsviridov 3y ago
I build pipes left to right, and I read pipes left to right...
1 -> 2 -> 3 is easier that (2 <- 1) -> 3
- samsquire 3y agoYou can put shell file redirections such as "< file" at the beginning of the line. In bash, type: < /etc/resolv.conf grep nameserver (That < is not a prompt, that's the less than symbol)
- tolciho 3y agoSometimes you can prefix with "< file". Sometimes, not so much. < /etc/passwd while IFS= read line || [ -n "$line" ]; do printf '%s\n' "$line"; done Meanwhile, in ZSH... Meanwhile, in languages that do not need IFS= and || [ -n "$line" ] checks...
- kzrdude 3y agoNice, I learned something and thank you
- ilyt 3y agoaliasing c to cat still requires less keystrokes
- antonvs 3y agoBut in a multi-step pipe, that’s still asymmetric and to me, less natural as a result. cat f | grep nameserver | otherproc… …is more consistently compositional.
- throwaway173738 3y agoThis is also the classic argument against reverse polish notation. Operator-first makes it harder to say the name of an operator in a sentence.
- ajuc 3y agoReverse polish notation is operator last.
- eru 3y agoOperator first makes the sentence easier: '+ 2 3' becomes 'add 2 and 3' In any case, it's a silly objection.
- pxc 3y agoIt's an especially silly objection in the case of the command line, where prefix notation is already the norm anyway. + 2 3 is naturally how you'd write addition if addition were a standalone Unix command!
- jrockway 3y agoInfix operators are very weird, though. They come from math, where every elementary school student has to memorize "please excuse my dear aunt sally" to be able to answer a simple question like "what is 2³ + 4 ÷ 2". C copied this concept, and nobody really ever bothered to memorize C's operator precedence, so they just end up writing Lisp but with the operators in the middle. pow(2, 3) + (4/2). Note that some operators appear prefix instead of infix for no apparent reason. (You can't just remember what you learned in math class when writing a computer program, because now we have bitwise and, or, xor, left shift, right shift, equality, pointer dereferencing, assignment, logical and, or, modulo, pre-increment, post-increment, bitwise not, logical not, etc. So you have to learn it all again. And it's different for every language.) Put everything up front, and suddenly you don't have to think about this anymore. (+ (expt 2 3) (/ 4 2)). The computer just does what you say and there are no rules to memorize. Personally, I always use RPN calculators (dc is my favorite), because I don't trust the calculator to remember operator precedence. They usually do it right, but it's difficult to reason about. (The example would be "2 3 ^ 4 2 / + p" in dc.)
- vram22 3y ago>every elementary school student has to memorize "please excuse my dear aunt sally" In Indian schools it used to be BODMAS, for Brackets Of Division Multiplication Addition Subtraction, for operator precedence, for which our teachers told us the mnemonic was badmaash, meaning a scoundrel or a villain, in Hindi. Guaranteed to make kids remember it. :) Of, as in half or a quarter or ... of some other number.