Re:When Bash scripts bite
by dtoma on Thursday May 11, 2017 @11:50PM
(#14321301)
Does error handling in your bash scripts ever become annoying enough to warrant a rewrite in, say, OCaml?
[ Parent
| on HN ]
Re:When Bash scripts bite
by MaxGabriel on Friday May 12, 2017 @01:07AM
(#14321568)
For context, since I think some people don't know this and are down voting you, this blog post is from Jane Street (probably the largest commercial OCaml deployment?). As another poster noted Haskell has many tools/libraries for writing scripts which makes dtoma's question very reasonable.
Definitely not OCaml, but usually python or ruby will do the job better.
Re:When Bash scripts bite
by BoorishBears on Friday May 12, 2017 @02:22AM
(#14321820)
We use node at work now. The fact is it's not worth it trying to get everyone to write good bash scripts. Js doesn't have nearly as many foot guns and there's a library for just about anything you could want to do.
Error handling in asynchronous JavaScript is quite notorious for being easy to screw up.
True for async code, but if you use something like ShellJS [1] (which would be an easy way to rewrite a bash script that was getting out of hand), all commands are synchronous, so error handling is just try/catch.
Re:When Bash scripts bite
by moosingin3space on Friday May 12, 2017 @03:48PM
(#14327279)
If only everyone used promises...I can dream, right?
Regardless, I'd actually prefer Haskell's do-notation for both asynchronous commands and shell-scripting tasks. Even though Haskell isn't my favorite language, do-notation is quite nice for this.
Just not left pad ;-)
It's happened! We have some internal magic that lets us run ml directly: ./my_bash_script_replacement.ml, and it makes replacements fairly painless.
But we don't do it often. Each language has its strengths and weaknesses, and the constraints of a small script tend not to change that much over time. The script either starts other executables and pipes some text around, or it does some computation. The choice of which to use is often (but not always) clear.
I'm not sure I agree with the "don't do it often". Having jane-script (which is our OCaml scripting system) has allowed us to greatly reduce our dependence on Bash.
That said, there are still little things we use Bash for. But our tolerance for large bash scripts has diminished greatly over the years.
Re:When Bash scripts bite
by ryanmccullagh on Friday May 12, 2017 @12:08AM
(#14321375)
I believe OCaml would be a horrible choice as a replacement for bash
Re:When Bash scripts bite
by Mathnerd314 on Friday May 12, 2017 @12:12AM
(#14321390)
Haskell has several shell-scripting libraries:
https://hackage.haskell.org/package/turtle
https://hackage.haskell.org/package/shelly
http://chrisdone.com/posts/shell-conduit
ocaml isn't that far off, just even less popular...
They do not seems to warrant further investigation, the examples you find about these implementations are overly simplified bordering useless. If you are going that way you might as well go with something like PowerShell, and that's a horrible scriping language.
Funny how ShellCheck mentioned above is written in Haskell :)
You might want to have a look at [bos]
Nope.
Re:When Bash scripts bite
by akhilcacharya on Friday May 12, 2017 @12:15AM
(#14321400)
I wonder if the answer is the same if your name is Yaron Minsky :)