6 ms·
This thread is likely a good place to ask: What modern alternatives to `.sh` scripting exist? Tcl? Is Fish objectively better than Bash and ZSH? Are there any
by pdimitar 6y ago
This thread is likely a good place to ask:
What modern alternatives to `.sh` scripting exist? Tcl? Is Fish objectively better than Bash and ZSH? Are there any thin wrappers and transpilers on top of sh? Or maybe just good old Perl?
And how does this project address normal pain points of shell scripting, like using arrays and iterating on them for example?
I was thinking a lot on the topic lately and currently have no good answers (never studied the topic in detail). I suppose just replacing `sh` scripting with Golang is also an option. Not the strongest typed or least verbosive language out there but it has a very good cross-compilation story, compiles really fast and produces single binaries that are easy to distribute. So might go with that.
Python is out because startup time wasn't great last I used it for CLI tools (might be an outdated info however, any metrics)? Ruby is also a pretty solid candidate; the lack of static typing is, eh, 50/50 -- might not be important after all.
I also know a guy who replaced Python with OCaml for quick scripting which is rather bizarre to me but knowing a bit more about OCaml nowadays, that actually can work just fine -- and OCaml is very terse.
I would prioritize speed of startup and terse code over everything else. Static typing I want but can very likely do without. I don't care much how portable the program/runtime is; I can distribute it to my machines and I have some influence in my work about what tooling to use.
Any practical recommendations?
- Y_Y 6y agoPerl, Julia, Python with PyPy, bash (but pretend it's something else)
- thaumasiotes 6y ago> I also know a guy who replaced Python with OCaml for quick scripting which is rather bizarre to me but knowing a bit more about OCaml nowadays, that actually can work just fine -- and OCaml is very terse. > I would prioritize speed of startup and terse code over everything else. If speed of startup and terse code are all you want... what's the problem with OCaml? It's got static typing too.
- pdimitar 6y agoThe only problem is that I'm a novice in it and it will take some significant investment of time and energy to learn it well. Which I still plan to do. Was just wondering if there are replacements for shell scripting that are quicker to learn.
- swirepe 6y agoWhat's wrong with bash? Specifically, what are you trying to do that you can't?
- pdimitar 6y agoWanted a `for` loop between two numbers, couldn't find a good way in 10 minutes, made the script require `zsh`.
- orbz 6y agoBash sequence expression didn't work? http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Brace-Expansion http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.h...
- pdimitar 6y agoYep, didn't know about that one. Guess my Google-fu failed me back then.
- m463 6y agowow, I was staring at it for a bit before I realized: for i in {1..10}; do echo $i; done worked and was equivalent to: for((i=1;i<=10;i++)); do echo $i; done for i in 1 2 3 4 5 6 7 8 9 10; do echo $i; done
- geocar 6y agoseq 5 10 | while read REPLY ... for x in `seq 5 10`; do ...
- AlchemistCamp 6y agoRuby is fantastic for scripting. It has quite a few of the same conveniences that made Perl great for scripting and it's a lot easier (for me at least) to maintain and understand when seeing it months or years later.
- freedomben 6y agoYes, yes yes. I started Ruby because I got a job at a Rails shop. I didn't like it all that much for a while, but then I decided to write a CLI program in Ruby and break out of rails. I quickly realized nearly everything I didn't like about "ruby" was actually rails. After a couple of years I moved on and don't do rails anymore, but I ruby is still my go to for any script that requires arrays or maps (the point where bash begins to be really painful). Ruby is the best scripting language ever IMHO*. Ruby one-liners (inherited from Perl tradition) make it plug nicely into a bash script also. * I haven't tried Julia yet but plan to.
- pdimitar 6y agoYep, I agree. Only used it twice years ago for that and as another sibling comment mentions, it is pleasant to use. How is the startup time though? That's important.
- AlchemistCamp 6y agoIt's about the same as JavaScript: > time ruby hello.rb Hello, world! ruby hello.rb 0.11s user 0.13s system 81% cpu 0.297 total > time node hello.js Hello, world! node hello.js 0.10s user 0.16s system 84% cpu 0.307 total
- pdimitar 6y agoYeah, 100-200ms are quite fine in fact. Maybe I got spoiled by Rust and OCaml that start in the matter of 3-8ms. :D But these Ruby and Node startup times are good.
- codemac 6y agoByron's rc. https://github.com/rakitzis/rc https://github.com/rakitzis/rc Sane quoting eliminates and a lack of recursive expansion make ssh a breeze. Pattern matching, backquote status, and pipe status simplification are all incredibly easy to get right. C-like syntax for blocks means nested hierarchies are easy to understand and to write correctly. Simple small binary, doesn't require readline and can be built for almost every architecture and OS.
- pdimitar 6y agoWasn't aware of that one and it looks very promising, thank you. Does it work with `parallel`? Or does it have a similar built-in facility itself?
- codemac 6y agoThere is very little built in, but this is an advantage. Yes GNU Parallel (that's what you're referring to I assume) can still run under rc, though I'm not sure exactly what makes you think it couldn't!
- pdimitar 6y agoI am just being paranoid at this point, nothing else. :) Thank you! Looks lightweight and less confusing. I'll give it a go.
- flaie 6y agoYou can definitely use Clojure using Babashka, https://github.com/babashka/babashka https://github.com/babashka/babashka
- mjul 6y agoNow that you mention OCaml, I have been using the OCaml dialect F# for scripting. It works just like any script (.fsx files) and you can also compile it ahead of time. There is a REPL for experimenting and the type system provides for a superior IDE experience. It has the full .NET ecosystem at its disposal. And algebraic data types to ensure you cover all edge cases. And last but not least - if you are scripting any kind of data wrangling, the Type Providers feature of F# offers a very powerful way to build those ETL jobs with type safety with just a few lines of code.
- pdimitar 6y agoAgreed on all accounts but still -- how is the startup time?
- mjul 6y agoFor my most common uses cases - daily jobs to fetch data from remote APIs, clean, transform and combining data sets in a batch pipeline - the startup time has not been an issue. Most steps are short scripts of a few hundred lines and compile quickly. Downloading dependencies (libraries) may take a while depending on how much you pull in from e.g. NuGet (seconds not minutes) but you can keep these between runs. For historical context, around 1994, I ditched shell with heavy awk and add use in favour of Perl to avoid the heavy overhead of multiple processes being spawned by the shell scripts. So you have to know both what you need but also which alternatives you are benchmarking it against.
- pdimitar 6y agoYeah, I can accept the argument that usually startup time doesn't matter. But since I finally got fed up with shell scripting, I want to find a proper viable long-term alternative. I know that for most of my scripts I won't care neither for startup time nor for strong typing (just an example, I know that OCaml and thus F# have it) won't be necessary. But I just want to have a powerful tool in my hands for those few outlier cases where you'll get pissed off at slow startup. But I can still agree with you! > For historical context, around 1994, I ditched shell with heavy awk and add use in favour of Perl to avoid the heavy overhead of multiple processes being spawned by the shell scripts. I feel a novice now. :D To be fair, there weren't things I wasn't able to achieve with zsh scripts and `parallel` and the usual suspects (sed, awk et. al.) but when I measure how much time -- and sometimes sanity -- I lose until I make something rather trivial work, the analysis isn't in favour of my current workflow. 500 "quick and dirty" scripts each wasting you 3h as opposed to 5-10 minutes amounts to a LOT of wasted work time. To be fair, I was not inclined to use F#. OCaml always impressed me with its amazingly fast compiler. But you have a very solid point that with F# you can use the entire .NET ecosystem... > So you have to know both what you need but also which alternatives you are benchmarking it against. I don't know exactly what I need, for the better or the worse. I just want to do one big switch (away from sh/bash/zsh scripting) and not have to redo it anytime soon, is all. Most tasks are I/O bound anyway so normal shell scripting and `parallel` can take you VERY far. But I've been bitten by weak typing and surprisingly parsed values so I am looking for something stricter. Runtime speed is hardly relevant to anything because again, I/O bound is the norm (_especially_ when you work with the network; most network-bound tasks that people put in their scripts nowadays could easily be handled by a Pentium III from back in the day, I feel).
- deleted 6y ago[deleted]