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.

  • bc3114@lemmy.ml
    link
    fedilink
    arrow-up
    15
    arrow-down
    1
    ·
    24 days ago

    luajit is small, fast(well, it can jit), and has a small but complete standard library and can do FFI pretty easily, should be ideal for most homelab usecase

    ldd $(which luajit)                                                                                
            linux-vdso.so.1 (0x00007ffee9dc7000)
            libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb4db618000)
            libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb4db613000)
            libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb4db5f3000)
            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb4db3ca000)
            /lib64/ld-linux-x86-64.so.2 (0x00007fb4db799000)
    
    • davel@lemmy.ml
      link
      fedilink
      English
      arrow-up
      3
      arrow-down
      1
      ·
      edit-2
      24 days ago

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

  • mub@lemmy.ml
    link
    fedilink
    arrow-up
    9
    ·
    22 days 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.

    • tankplanker@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      22 days 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.

  • cmhe@lemmy.world
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    24 days ago

    What about Lua/Luajit?

    In most scripting languages you have the interpreter binary and the (standard) libraries as separate files. But creating self-extracting executables, that clean up after themselves can easily be done by wrapping them in a shell script.

    IMO, if low dependencies and small size is really important, you could also just write your script in a low level compiled language (C, Rust, Zig, …), link it statically (e.g. with musl) and execute that.

    • slembcke@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      23 days ago

      I use Lua for this sort of thing. Not my favorite language, but it works well for it. Easy to build for any system in the last 20-30 years, and probably the next 20 too. The executable is small so you can just redistribute it or stick it in version control.

  • digdilem@lemmy.ml
    link
    fedilink
    English
    arrow-up
    8
    arrow-down
    1
    ·
    23 days 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.

  • Nibodhika@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    24 days ago

    Realistically whatever problems you see in python will be there for any other language. Python is the most ubiquitously available thing after bash for a reason.

    Also you mentioned provisioning scripts, is that Ansible? If so python is already there, if you mean really just bash scripts I can tell you that does not scale well. Also if you already have some scriptsz what language are they on? Why not write the function there?

    Also you’re running syncthing on these machines, I don’t think python is larger than that (but I might be wrong).

    • gomp@lemmy.mlOP
      link
      fedilink
      arrow-up
      1
      ·
      23 days ago

      Also you mentioned provisioning scripts, is that Ansible? If so python is already there, if you mean really just bash scripts I can tell you that does not scale well. Also if you already have some scriptsz what language are they on? Why not write the function there??

      Currently it’s mostly nixos, plus a custom thing that generates preconfigured openwrt images that I then deploy manually. I have a mess of other vms and stuff, but I plan to phase out everything and migrate to nixos (except the openwrt stuff, since nixos doesn’t run on mips).

      I don’t really need to run this specific synchthing-ID script except on my PC (I do the provisioning from there), but I have written scripts that run on my router (using busybox sh) and I was wondering if there is a “goto” scripting that I can use everywhere.

    • digdilem@lemmy.ml
      link
      fedilink
      English
      arrow-up
      2
      ·
      23 days ago

      So often the right answer, perl. It’s a shame that it’s so unfashionable these days.

  • Penta@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    24 days ago

    Maybe something like Elvish or Nushell could be worth a look. They have a lot of similarities to classic shells like bash, but an improved syntax and more powerful features. Basically something in between bash and Python. Not sure about disk footprint or general availability/portability though

  • x1gma@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    23 days ago

    The smallest footprint for an actual scripting probably will be posix sh - since you already have it ready.

    A slightly bigger footprint would be Python or Lua.

    If you can drop your requirement for actual scripting and are willing to add a compile step, Go and it’s ecosystem is pretty dang powerful and it’s really easy to learn for small automation tasks.

    Personally, with the requirement of not adding too much space for runtimes, I’d write it in go. You don’t need a runtime, you can compile it to a really small zero dependency lib and you have clean and readable code that you can extend, test and maintain easily.

  • moonpiedumplings@programming.dev
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    22 days 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:

  • Ramin Honary@lemmy.ml
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    23 days ago

    I would go with Guile, because it is built-in to the Guix Package Manager which is a really good general-purpose package manager.

    It ticks several of your boxes:

    • has a CLI interpreter
    • is a general purpose language, Scheme, amd compliant with revisions 5, 6, and 7 of the language standard
    • allows writing in a functional style (it is one of the original functional programming languages)
    • small disk footprint, but still large enough to be “batteries included”
    • decent documentation, especially if you use Emacs
    • simple setup: not so much, unless you are using Guix to begin with. The standard distribution ships with lots of pre-built bytecode files, you need an installer script to install everything.

    It also has pretty good libraries for system maintenance and reporting:

  • undrivendev@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    22 days ago

    Python.

    Just remember to use pyenv for interpreter installation, version and environment management. It’s pretty straightforward that way and you have predictability.

    Don’t ever manually fiddle with the system python and/or libraries or you’ll break your system. You should just rely on the package manager for that.

  • GissaMittJobb@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    23 days ago

    I don’t know if it matches your desire for easy install of small disk space, but it might make up for it in other arenas - Ruby is my new-found love when making simple scripts. Being able to mostly emulate the shell integration that bash has by just using backticks to call a shell command is the killer feature in my book.