3 ms·
The 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 so
by its-summertime 2y ago
The 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,
`< x head` just attaches `x`'s fd to stdin.
In this way, treating a file like a "light-weight" command (light-weight because no backing process) makes more sense, `open x | head` perhaps
Though I will note that, in a way, bash supports this, as it has a modules system, and one of the pre-existing modules in the source tree is a `cat` replacement, through my lack of understanding of C prevents me from working out if its optimal
https://git.savannah.gnu.org/cgit/bash.git/tree/examples/loadables/cat.c https://git.savannah.gnu.org/cgit/bash.git/tree/examples/loa...
- rolfan 2y agoFrom the file you linked, the built-in just copies the input files one by one, sequentially, into stdin. All done in chunks of 4096 bytes, a common page size. 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.