3 ms·
> Honestly, though? The right answer is to transpile a better language to Sh. I like this, but I think it's even better to just escape sh entirely. If you are
by norir 3y ago
> Honestly, though? The right answer is to transpile a better language to Sh.
I like this, but I think it's even better to just escape sh entirely. If you are on a system that supports sh, it almost certainly has a c99 compatible compiler which can be used to install lua(JIT)? or another better scripting language. I wrote a little script idempotently installs lua 5.4 (that I tried to include but HN formatting messed up) and then runs a luascript embedded in a heredoc. The first time I ran it, it took 5.4 seconds to print "Hello, world!" including downloading the lua source code from their website and compiling the whole thing. The second time it took 11ms. I really see no great reason to continue using sh for anything new except for the purpose of installing something else.
- nextos 3y agoBash and most alternatives are full of footguns. However, they are really convenient to glue together different components, e.g. a data preprocessing system. Personally, the way I avoid footguns is to use a functional style. Filter instead of conditions and map instead of loops. GNU Parallel makes this straightforward, including distributed commands across machines! Aside, it is easy to emulate relational algebra with grep, sed, and awk. A good essay describing some of the advantages of this approach is: http://widgetsandshit.com/teddziuba/2010/10/taco-bell-programming.html http://widgetsandshit.com/teddziuba/2010/10/taco-bell-progra...
- SomeCallMeTim 3y ago"Install something else" is ... a nice idea? But it's simply not realistic. Examples: - Embedded devices that may or may not have an internet connection - Government classified networks that aren't allowed to grab ANY random software off of the internet - Simply not wanting to add another dependency to an operation. I'm a former Lua fan. I've ... written it off at this point. [1] Honestly if I were to take the approach you describe, I'd likely instead have the shell script only look at the architecture and then choose one of 2-3 precompiled Go binaries. Talk about simple and fast...and the binaries could be hosted behind a firewall somewhere. Or maybe I was thinking of it wrong. Just embed the various Go binaries into a tar file embedded right in the shell script[2], and choose the right one based on architecture. Done. :) [1] https://realmensch.org/2016/05/28/goodbye-lua/ https://realmensch.org/2016/05/28/goodbye-lua/ [2] https://www.xmodulo.com/embed-binary-file-bash-script.html https://www.xmodulo.com/embed-binary-file-bash-script.html