5 ms·
Does error handling in your bash scripts ever become annoying enough to warrant a rewrite in, say, OCaml?
by dtoma 9y ago
Does error handling in your bash scripts ever become annoying enough to warrant a rewrite in, say, OCaml?
- iblaine 9y agoNope.
- akhilcacharya 9y agoI wonder if the answer is the same if your name is Yaron Minsky :)
- mijoharas 9y agoI don't understand why you got downvotes, makes a lot of sense as a question (and made me smile) :).
- ryanmccullagh 9y agoI believe OCaml would be a horrible choice as a replacement for bash
- Mathnerd314 9y agoHaskell has several shell-scripting libraries: https://hackage.haskell.org/package/turtle https://hackage.haskell.org/package/turtle https://hackage.haskell.org/package/shelly https://hackage.haskell.org/package/shelly http://chrisdone.com/posts/shell-conduit http://chrisdone.com/posts/shell-conduit ocaml isn't that far off, just even less popular...
- emj 9y agoThey 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.
- ujal 9y agoFunny how ShellCheck mentioned above is written in Haskell :)
- mseri 9y agoYou might want to have a look at [bos] [bos]: http://erratique.ch/software/bos http://erratique.ch/software/bos
- viraptor 9y agoDefinitely not OCaml, but usually python or ruby will do the job better.
- BoorishBears 9y agoWe 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.
- foota 9y agoJust not left pad ;-)
- mbrock 9y agoError handling in asynchronous JavaScript is quite notorious for being easy to screw up.
- nilliams 9y agoTrue 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. [1] https://www.npmjs.com/package/shelljs https://www.npmjs.com/package/shelljs
- moosingin3space 9y agoIf 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.
- deleted 9y ago[deleted]
- MaxGabriel 9y agoFor 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.
- cgaebel 9y agoIt'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.
- yminsky 9y agoI'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.