I’ve been looking around for a scripting language that:

  • has a cli interpreter
  • is a “general purpose” language (yes, awk is touring complete but no way I’m using that except for manipulating text)
  • allows to write in a functional style (ie. it has functions like map, fold, etc and allows to pass functions around as arguments)
  • has a small disk footprint
  • has decent documentation (doesn’t need to be great: I can figure out most things, but I don’t want to have to look at the interpter source code to do so)
  • has a simple/straightforward setup (ideally, it should be a single executable that I can just copy to a remote system, use to run a script and then delete)

Do you know of something that would fit the bill?


Here’s a use case (the one I run into today, but this is a recurring thing for me).

For my homelab I need (well, want) to generate a luhn mod n check digit (it’s for my provisioning scripts to generate synchting device ids from their certificates).

I couldn’t find ready-made utilities for this and I might actually need might a variation of the “official” algorithm (IIUC syncthing had a bug in their initial implementation and decided to run with it).

I don’t have python (or even bash) available in all my systems, and so my goto language for script is usually sh (yes, posix sh), which in all honestly is quite frustrating for manipulating data.

  • @[email protected]
    link
    fedilink
    710 months ago

    Technically, you could bundle a Perl script with the interpreter on another system using pp and run the packed version on systems with no installed Perl, but at that point you might as well just use a compiled language.

  • @[email protected]
    link
    fedilink
    6
    edit-2
    10 months ago

    Not quite a scripting language, but I highly recommend you check out cosmo for your usecase. Cosmopolitan, and/or Actually Portable Executable (APE for short) is a project to compile a single binary in such a way that is is extremely portable, and that single binary can be copied across multiple operating systems and it will still just run. It supports, windows, linux, mac, and a few BSD’s.

    https://cosmo.zip/pub/cosmos/bin/ — this is where you can download precompiled binaries of certain things using cosmo.

    From my testing, the APE version of python works great, and is only 34 megabytes, + 12 kilobytes for the ape elf interpreter.

    In addition to python, cosmopolitan also has precompiled binaries of:

    • Janet 2.5 MB
    • Berry 4.0 MB
    • Python 34 MB
    • Php 11 MB
    • Lua 2.1 MB
    • Bash 5.1 MB

    And a few more, like tclsh, zsh, dash or emacs (53 MB), which I’m pretty sure can be used as an emacs lisp intepreter.

    And it should be noted these may require the ape elf interpeter, which is 12 kilobytes, or the ape assimilate program, which is 476 kilobytes.

    EDIT: It also looks like there is an APE version of perl, and the full executable is 24 MB.

    EDIT again: I found even more APE/cosmo binaries:

  • SuperFola
    link
    fedilink
    English
    4
    edit-2
    10 months ago

    If you are interested in tiny lisp like languages, this gitlab could be of interest to you.

    Full disclaimer, I came across it a few years back as I am the maintainer of arkscript (which will get faster and better in the v4, so that data about it there is accurate as a baseline of « it should be at least this good but can be even better now »).

  • Joe
    link
    fedilink
    2
    edit-2
    10 months ago

    It is possible to wrap something like python into a single file, which is extracted (using standard shell tools) into a tmpdir at runtime.

    You might also consider languages that can compile to static binaries - something like nim (python like syntax), although you could also make use of nimscript. Imagine nimscript as your own extensible interpreter.

    Similarly, golang has some extensible scripting languages like https://github.com/traefik/yaegi - go has the advantage of easy cross compiling if you need to support different machine architectures.

  • mub
    link
    fedilink
    1210 months ago

    I honestly love Powershell, but haven’t tried the Linux version yet. I only use Bash on linux but it has a load of odd quirks that make it unpleasant to use imo. Can’t comment on anything else.

    • @[email protected]
      link
      fedilink
      110 months ago

      I use powershell for work as I need the m365 modules for work and its very flexible with decent module availability to plug in all sorts.

      However it absolutely sucks for large data handling, anything over 10k rows is just horrendous, I typically work with a few million rows. You can make it work with using .Net to process it within your script but its something to be aware of. Being able to extend with .Net can be extremely useful.

  • @[email protected]
    link
    fedilink
    110 months ago

    Not sure how big node footprint is but would fit the bill. Would only recommend if you wanna go into web dev career in the future tho 🙃

  • @[email protected]
    link
    fedilink
    410 months ago

    (Chicken) Scheme.

    Schemes have one of the best and most interactive interpreters Is general purpose, allows functional, procedural and OO programming, small disk size and compilable to native executables, Throughout documented and supplemented by years of research, simple setup.

    It also is CGI compatible, if necessary.

  • @[email protected]
    link
    fedilink
    English
    310 months ago

    Bro seriously just slap pyenv + pyenv-virtualenv on your systems and you’re good to go. They’re absolutely trivial to install. Iirc the latter is not a thing in windows, but if you’re stuck on windows for some reason and doing any serious scripting, you should be using WSL anyways.

  • combat_brandonism [they/them]
    link
    fedilink
    English
    210 months ago

    Could use a hipster shell like fish, nushell or elvish. I know the latter two have the functional support you’re looking for.

    • davel [he/him]
      link
      fedilink
      English
      5
      edit-2
      10 months ago

      That does seem to be just one, maybe two small files, and no dependencies. And a built in map() function.

  • @[email protected]
    link
    fedilink
    Akan
    110 months ago

    vlang might fit your request pretty nicely. It’s a bit patchy in places but mainly stable and gets pretty frequent updates

  • ZWQbpkzl [none/use name]
    link
    fedilink
    English
    410 months ago

    Elixir checks most of those boxes. If you want a good functional scriptibg language, Elixir soynds like the go to. Some lisp language like guile should also be sufficient, and probably have a lighter footprint.

    This requirement stands out though:

    has a simple/straightforward setup (ideally, it should be a single executable that I can just copy to a remote system, use to run a script and then delete)

    Thats basically what ansible does. If you plan on doing this to multiple machines you should just use ansible. Also how do you plan on ensuring the scripting interpreter is installed on the machines?

    • @[email protected]OP
      link
      fedilink
      110 months ago

      Elixir is quite big (yeah, it’s certainly smaller than something like java… sorry for not specifying what I mean by “small disk footprint”).

      Thats basically what ansible does. Thats basically what ansible does. If you plan on doing this to multiple machines you should just use ansible.

      Ansible requires python on the target machine (or a lot of extra-hacky workarounds) so… I could just use python myself :)

      BTW getting ansible to do anything besides the very straightforward usecases it was meant for is a huge pain (even a simple if/else is a pain) and it’s also super-slow, so I hate it passionately.

      Also how do you plan on ensuring the scripting interpreter is installed on the machines?

      Ideally I’d just copy the interpreter over via ssh when needed (or install it via the local package manager, if it’s available as a package)

      • ZWQbpkzl [none/use name]
        link
        fedilink
        English
        110 months ago

        If python is too big for you and you’re dealing with heterogeneous systems then you’re probably stuck with sh as the lowest common denominator between those systems. I’m not aware of any scripting languages that are so portable you can simply install them with one file over scp.

        Alternate route is to abandon a scripting interpreter completely and compile a static binary in something like Go and deploy the binary.

        There was also some “compile to bash” programming languages that I’ve sneered at because I couldn’t think of a use case but this might be one.

  • @[email protected]
    link
    fedilink
    5
    edit-2
    10 months ago

    JavaScript through Node.js, or TypeScript through Deno if you like typed languages. They both check all your boxes (just check the size of the executables to make sure that it’s what you would consider “small footprint”).

    Both languages and runtimes are quite popular, so you will find any answers on StackOverflow.

    They are both single-executable with little dependencies, and Deno can also compile your scripts to self-contained executables.

    As a bonus, both support the vast and extensive NPM package repository where you can find all sort of libraries for even the most complex tasks.

    And they work with your favourite IDE or editor, not just syntax highlighting, but also contextual suggestions.

    • @[email protected]
      link
      fedilink
      English
      210 months ago

      As a Java developer, and someone who never learned Python or other scripting languages, Node is my go-to scripting language. I’ve only come around to it for that in the past year or two. But it’s great.

    • @[email protected]OP
      link
      fedilink
      410 months ago

      Installing node uses some 60MB (according to zypper on my current desktop). I’d rather have something small and possibly that consists of a single executable.

      As a bonus, both support the vast and extensive NPM package repository

      That’s not necessarily a feature :) Package repos are great if you are a developer (I am one) working primarily with that language, but are frustrating if you just want to run things.

      • @[email protected]
        link
        fedilink
        1
        edit-2
        10 months ago

        I thought so. Although almost nothing for modern standards, 60MB is not exactly tiny. Sorry about that.

        On a different note, a repository is always a good thing imho. If you’d rather not have to worry about the dependency-pull step you can always include the dependencies with your sources, or just limit your code to using features included in the standard library.

  • DigitalDilemma
    link
    fedilink
    English
    1810 months ago

    Perl is already installed on most linux machines and unless you start delving into module usage, you won’t need to install anything else.

    Python is more fashionable, but needs installing on the host and environments can get complicated. I don’t think it scales as well as Perl, if that’s a concern of yours.