Re:Use Haskell for shell scripting
by Gabriel439 on Friday January 30, 2015 @02:40PM
(#8973960)
There are two ways you can embed that within `turtle`. You can either embed each step as its own concurrent process, like this:
-- Note, the flow is right-to-left, not left-to-right
inshell "bar" (inshell "fgrep ..." (inshell "foo" empty))
Or you can just embed the entire thing within a single `inshell` command: inshell "foo | fgrep ... | bar"
The reason this works is that the type of `inshell` is: inshell
:: Text -- Command line
-> Shell Text -- Standard input to feed
-> Shell Text -- Standard output from command
This leads you stream to any shell command's input and read the command's output also as a stream.
Here's a pattern that comes up fairly frequently for me:
It uses the second column in info.csv as fixed strings to match inside lines in the output of foo, and filters them out, with the remaining lines going to bar.All 4 processes (foo, bar, fgrep, cut) run concurrently. Likely fgrep will block on cut sooner or later, but the point is that multiple communicating concurrent processes are set up using a fairly easy to use DSL.
That's what a shell is, to me.