81
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 02 Sep 2023
81 points (88.6% liked)
Programming
17314 readers
368 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 1 year ago
MODERATORS
I write a lot of bootstrapping scripts, and I have a solution thats probably something you and others in this thread have never seen before. You can write a single script in a full/normal language, no compilation step, and it works on systems that only have bash/sh. It doesn't compile to bash, or at least not in the way you might think/expect it to, but it should do what you want.
(guillotine because it's a universal executor) https://github.com/jeff-hykin/deno-guillotine
This^ one uses Deno/JavaScript, but in principle it might be possible to do with other languages. It definitely requires some explanation, so I'll try to give that here;
As another person said, shells are not nearly as standardized as we need them to be. Mac uses zsh, Ubuntu uses dash, neither store a posix bash exectuable in the same place, and both have
ls
andgrep
differences that are big enough to crash common scripts. Even if you're super strict on POSIX compliance, common things will still break if you write a big script (or trying to compile a big program to bash).I hate JS as much as the next guy, but it is possible to write a single text file that is valid bash/dash/zsh/powershell and valid JavaScript all at the same time. It sounds impossible, but there is enough overlapping syntax that actually any javascript program can be converted into a valid bash script without mangling the JS code. It might be possible to do for python as well.
POSIX is good enough for making a small, carefully-crafted well-tested OS-detecting caveat-handling script. So that's exactly what we do; use a small shell script at the top to ensure that the JS runtime you want is installed (auto install if missing). Then the script executes itself again using the JS runtime. It wasn't easy but I a made a library that explains how it's possible and gives a cli tool that automates it for the Deno runtime (the link I posted above).
After that, I just recreated tools that feel like bash, but this time they are actually cross platform. Ex:
I picked Deno because it auto installs libraries (imports directly from URL so users don't have to install anything)
Okay at first I was pretty convinced that this was just the wrong way to accomplish what I thought your goal was. But now, after reading the StackOverflow post and your README, I think this is fascinating and frankly really awesome. What a clever and strange thing, using multiline comments that way, and string no-ops. I think just knowing this exists will cause me to find reason to use it.