4 ms·
This blogger does not seem to know that in the POSIX shell syntax, redirections can be specified anywhere in the command: < access.log head -n 500 | grep ma
by kazinator 3y ago
This blogger does not seem to know that in the POSIX shell syntax, redirections can be specified anywhere in the command:
< access.log head -n 500 | grep mail | perl -e
Now you can delete "head -n 500 |".
> If we then delete only the head processing step we’re left without a step that transforms the string access.log into the contents of the access log.
By introducing "cat access.log" we have the same problem: if we delete only the cat processing step, we're left without a step that transforms the string access.log into the contents. For the useless cat to have the nice property that you can cleanly delete it from the command line, you need:
< access.log | cat | head -n 500 ...
:)
- jameshart 3y agoThe useless cat plays the role of ‘a process that produces a stream’, which gives you higher confidence that you can substitute it with a different ‘process that produces a stream’ - like the curl command mentioned in the article, or perhaps a server whose stdout output you want to analyse. It should be the same as giving your pipeline a file input handle via < access.log… but why take the risk?
- kazinator 3y agoThat's the whole mistake. Streams are not sourced by processes, but by kernel objects. You don't need a process to read bytes from a serial port, for instance. You don't need "cat /dev/ttywhatever | program". Interrupt handlers in the drivers already drive the activity of bytes being received.
- Bost 3y agoI'm sorry, that doesn't work: $ echo "foo" > access.log # create the access.log with some content $ < access.log | cat | head -n 5 # no output This works: $ cat access.log | head -n 5 foo $ < access.log cat | head -n 5 foo $ < access.log cat | cat | head -n 5 foo $ < access.log head -n 5 foo