3 ms·
I see 2 possible rationales to transpile to posix sh: 1: To remove bashisms/kshisms/zshisms to create output that works on ash/dash/busybox/xenix/sun/... In w
by Brian_K_White 5y ago
I see 2 possible rationales to transpile to posix sh:
1: To remove bashisms/kshisms/zshisms to create output that works on ash/dash/busybox/xenix/sun/... In which case, the more useful source language is bash or ksh etc, not a new invented one.
2: To generate a portable output like above from a better language than any *sh (*). In which case the source language should be something already common like python or perl or ruby etc (even if just a subset).
In either of those two use cases, I don't think it makes a great deal of sense to make a new language, and especially not to write the compiler for it in V of all things.
That relegates the whole project to being just a curiosity or a purely academic excercise.
(*) I use every trick bash and ksh offer, so I know it's possible to do all kinds of stuff in some *sh's, but a lot of the features in them are encoded into practically inscrutable special syntax and rules and tricks, where more purpose built programming languages make all the features more explicit and spelled out -> readable. bash is a powerful enough language, but not a readable one, except for rairly stupid scripts that either don't do much, or do everything the hard way.
- maxbond 5y agoWhat about, to gain saner semantics (static typing) while retaining the portability and versatility of shell scripts?
- chalst 5y agoTypical shell programming idioms are quite dynamic. You can give saner semantics, allowing a fair amount of static checking, without abandoning this dynamicity. What Andy Chu has been doing with Oil Shell is promising in this respect. It supports optional type annotations. Cf. https://www.oilshell.org/blog/2021/01/why-a-new-shell.html https://www.oilshell.org/blog/2021/01/why-a-new-shell.html
- Brian_K_White 5y ago"What about, to gain saner semantics (static typing) while retaining the portability and versatility of shell scripts?" I think I was insufficiently critical in a misguided intention to be nice. Let me correct that a little :) If the need is great enough for a DSL, then the need is great enough for python or c or any of 100 other fully fledged universally available languages, and either require it's interpreter or ship a binary. However annoying it may be to require a ruby interpreter or something, there is essentially no case where the most sensible answer is this "Vala-for-sh". It's the worst of all worlds. Taking the whole life cycle into account, it's not saner or portable or versatile, it reduces all of those.
- deleted 5y ago[deleted]
- d0mine 5y agoDo you know of any "common language"-like (e.g., Python-like subset/DSL) that compiles to sh, to enable `curl -sSL https://tool.example.org/install https://tool.example.org/install | sh` use-case.