Earlier quoted context omitted.
In fact, I don't like people optimizing shell scripts for performance. I mean, shell scripts are slow by design and if you need something fast, you choose the wrong technology in the first place. Instead, shell script should be optimized for readability and portability and I think it is much easier to understand something like 'read | change >write' than 'change write'. So I like to write pipelines like this: cat foo…
This is a very silly way of writing it though. grep|sed can almost always be replaced with a simple awk: awk '/^x/ { sub("a", "b"); print $2; }' foo.txt. This way, the whole command fits on one line. If it doesn't, put your awk script in a separate file and simply call it with "awk -f myawkscript foo.txt".
For the Love of Pipes
141–150 of 323 posts
Re: For the Love of Pipes
#142Fully agree, pipes are awesome, only downside is the potential duplicate serialization/deserialization overhead. Streams in most decent languages closely adhere to this idea. I especially like how node does it, in my opinion one of the best things in node. Where you can simply create cli programs that have backpressure the same as you would work with binary/file streams, while also supporting object streams. process.…
Re: For the Love of Pipes
#143I gave a talk about including a bit about pipes in Angular: https://youtu.be/Gv7IfU78vxw?t=578
Re: For the Love of Pipes
#144I'm probably nitpicking, but if you're using cat to pipe a single file into the sdtin of another program, you most likely don't need the cat in the first place, you can just redirect the file to the process' stdin. Unless, of course, you're actually concatenating multiple files or maybe a file and stdin together. Disclaimer: I do cat-piping myself quite a bit out of habit, so I'm not trying to look down at the author…
In fact, I don't like people optimizing shell scripts for performance. I mean, shell scripts are slow by design and if you need something fast, you choose the wrong technology in the first place. Instead, shell script should be optimized for readability and portability and I think it is much easier to understand something like 'read | change >write' than 'change write'. So I like to write pipelines like this: cat foo…
Re: For the Love of Pipes
#145Earlier quoted context omitted.
In fact, I don't like people optimizing shell scripts for performance. I mean, shell scripts are slow by design and if you need something fast, you choose the wrong technology in the first place. Instead, shell script should be optimized for readability and portability and I think it is much easier to understand something like 'read | change >write' than 'change write'. So I like to write pipelines like this: cat foo…
This is a very silly way of writing it though. grep|sed can almost always be replaced with a simple awk: awk '/^x/ { sub("a", "b"); print $2; }' foo.txt. This way, the whole command fits on one line. If it doesn't, put your awk script in a separate file and simply call it with "awk -f myawkscript foo.txt".
That should be gsub, shouldn't it? (sub only replaces the first occurrence)
Re: For the Love of Pipes
#146Re: For the Love of Pipes
#147Why isn't the pipe a construct that has caught on in 'proper' languages?
The shell have the weird(?) behavior of ONE input and TWO outputs (stdout, stderr).
Also, can redirect in both directions. I think a language to be alike pipes, it need each function to be alike:
fun open(...) -> Result(Ok,Err)
and have the option of not only chain the OK side but the ERR: open("file.txt") |> print !!> raise |> print
exist something like this???Re: For the Love of Pipes
#148Cool, the pipe command must be one of the most essential things in Unix/Linux based systems. I would have loved to see some awesome pipe examples though.
Re: For the Love of Pipes
#149Earlier quoted context omitted.
The core critique - that everything is stringly typed - still holds pretty well though. >The receiving and sending processes must use a stream of bytes. Any object more complex than a byte cannot be sent until the object is first transmuted into a string of bytes that the receiving end knows how to reassemble. This means that you can’t send an object and the code for the class definition necessary to implement the ob…
To be fair, the same critisim could be used for a socket? I think the issue is that some people want pipes to be something magical that connects their software, not a dumb connection between them.
Im working on a library for this kind of intra-pipeline negitiation. It's all drawing-board stuff right now but I coobbled together a proof of concept:
https://unix.stackexchange.com/a/495338/146169
Do you think this is a reasonable way to achieve the magic that some users want in their pipelines? Or are ancient Unix gods going to smite me for tampering with the functional consistency of tools by making their behavior different in different contexts?
Re: For the Love of Pipes
#150Earlier quoted context omitted.
100% agree. Having to extract information with regular expressions is a waste of time. If the structure of the data was available, you would have type safety / auto-completion. You could even have GUIs to compose programs.
I hear what you're saying. However, how can you ensure the output type of one program matches the input type of another?