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.

  • mub@lemmy.ml
    link
    fedilink
    arrow-up
    12
    ·
    1 month 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
      ·
      1 month 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.

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

  • tiredofsametab@fedia.io
    link
    fedilink
    arrow-up
    4
    ·
    1 month ago

    Perl or python for things likely to already be there. Maybe ruby or PHP if you must. I used to work in groovy a lot but I think it requires the JVM

    • atzanteol@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      4
      ·
      1 month ago

      Perl requres the perl interpreter and python requires a python interpreter. Why is it bad that groovy also needs a vm?

      • nyan@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        1 month ago

        Last I checked, the JVM was larger than the standard Perl and Python interpreters, and had a much worse startup time (which is bad for short scripts).

          • nyan@sh.itjust.works
            link
            fedilink
            arrow-up
            1
            ·
            1 month ago

            Dude, I’ve worked with all these interpreters. The JVM’s startup is slow, although there’s been some improvement since the version 1.1 that I started out with. The interpreter speed is quite good once it gets going, so it remains a good choice for long-running or interactive programs where the startup is insignificant as a fraction of total program run-time, but if you’re running a script that takes only a fraction of a second to execute, the JVM’s startup can lengthen the time by an order of magnitude or more. Horses for courses and all that—I wouldn’t write a complex interactive GUI program in Perl, either.

      • digdilem@lemmy.ml
        link
        fedilink
        English
        arrow-up
        3
        ·
        1 month ago

        Perl’s core to most distros and will be there already. Python isn’t and can be quite heavy - plus some of are are still smarting over the major version change breaking everything and the need for complicated environments.

          • digdilem@lemmy.ml
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 month ago

            I work at scale - deploying scripts to hundreds of linux machines and any package you install will be multiplied that many times on the backend storage. You don’t get the luxury of installing anything that isn’t essential.

            • atzanteol@sh.itjust.works
              link
              fedilink
              English
              arrow-up
              1
              arrow-down
              2
              ·
              1 month ago

              Ohhh, you work at scale do you? With… “hundreds” of Linux servers? And 50MB, which is basically a rounding error for most storage solutions, will break your bank? Sure Jan.

  • davel [he/him]@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    1 month ago

    perl might be on all your systems. It’s kind-of a legacy, but still actively developed. It’s not a great language: it looks like bash scripting on steroids. But if you just need to write some small scripts with a language more powerful than awk or bash, it does the job. If perl isn’t on all of your systems already, then I would choose a better scripting language.

    • Findmysec@infosec.pub
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 month ago

      TBH I don’t even use awk that much, even that is plenty powerful for my needs. Perl absolutely blows my mind with how needlessly complex I can make stuff with it

      • silasmariner@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        1 month ago

        Everyone always dunkin’ on Perl, but I can’t even tell you how often it’s been the best tool for the job. Like, at least 3

  • Nibodhika@lemmy.world
    link
    fedilink
    arrow-up
    12
    ·
    1 month 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
      ·
      1 month 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.

  • undrivendev@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    1 month 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.

  • Aquila@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    1 month 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 🙃

  • bc3114@lemmy.ml
    link
    fedilink
    arrow-up
    34
    arrow-down
    1
    ·
    1 month 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)
    
  • fubarx@lemmy.ml
    link
    fedilink
    arrow-up
    4
    ·
    1 month ago

    Tried bash, Make, and awk/sed. All hit brick walls. Finally landed on pyinvoke. Two dependencies to install on any new machine. Never had problems. Also, easy to debug and modify as projects evolve.

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

      I fear I am not enough reverse (or Polish, for that matter) :)

      Anyway, I have great esteem for you (if you actually use forth and are not just trolling)

      • Paardendrummer@todon.eu
        link
        fedilink
        arrow-up
        1
        ·
        1 month ago

        @gomp Well no I know someone who does forth, not me really. Perhaps forth is just too low-level for anything except hardware drivers and so.

  • mryessir@lemmy.sdf.org
    link
    fedilink
    arrow-up
    4
    ·
    1 month 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.

  • GissaMittJobb@lemmy.ml
    link
    fedilink
    arrow-up
    7
    ·
    1 month 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.

  • gravitas_deficiency@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    3
    arrow-down
    1
    ·
    1 month 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.