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.

  • SuperFola
    link
    fedilink
    English
    4
    edit-2
    11 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 »).

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

    Perl would be my candidate for more advanced text handling than what sh can do.

    Never used Lua but I think it’s fun.

    If nothing else works, just learn C/Rust. There’s plenty of that on Linux systems, I think you’ll be able to manage. Yes, it doesn’t meet a lot of your requirements.

    • DigitalDilemma
      link
      fedilink
      English
      311 months ago

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

  • @[email protected]
    link
    fedilink
    1211 months 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).

    • @[email protected]OP
      link
      fedilink
      111 months 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.

  • combat_brandonism [they/them]
    link
    fedilink
    English
    211 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.

  • ZWQbpkzl [none/use name]
    link
    fedilink
    English
    411 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
      111 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
        111 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]OP
      link
      fedilink
      111 months 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
        link
        fedilink
        111 months 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.

  • @[email protected]
    link
    fedilink
    411 months 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.

  • @[email protected]
    link
    fedilink
    6
    edit-2
    11 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:

  • @[email protected]
    link
    fedilink
    10
    edit-2
    11 months 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.

  • @[email protected]
    link
    fedilink
    1611 months ago

    Only 5 years ago, everybody would be singing and shouting “perl”.

    Nowadays it is python that has taken this position (even though Perl is still there and can do so much more).

        • davel [he/him]
          link
          fedilink
          English
          211 months ago

          Go isn’t a scripting language, and it isn’t a system language either, despite what Wikipedia currently says. To be a system language, a language should support assembly language and shouldn’t require an embedded garbage collector. And if you’re going to make a compiled language anyway, why not make it capable of system work? Go is a platypus that’s popular with devops for some reason—probably Google’s clout in the industry.

          • Possibly linux
            link
            fedilink
            English
            211 months ago

            The one thing Go does have going for is performance. It compiles and runs pretty fast. It isn’t as fast as C but it is very close.

    • davel [he/him]
      link
      fedilink
      English
      311 months ago

      Why would you say that Perl “can do so much more” than Python? That assertion sounds indefensible.

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

        Even after using CPAN ? I found Perl to be much more “manageable” than Python.

        Python with Venv and Pip at least works as expected. Which makes it easier.

        • Possibly linux
          link
          fedilink
          English
          111 months ago

          Python has a clean syntax and is popular. I can’t say the same for Perl. Also I’m not sure if Perl is cross platform.

    • DigitalDilemma
      link
      fedilink
      English
      2
      edit-2
      11 months ago

      I used it for scripting a decade after everyone else, but even I have to admit PHP is rarely the best choice now.

    • lemmyvore
      link
      fedilink
      English
      1
      edit-2
      11 months ago

      I’ve actually tried using PHP on OpenWRT and embedded before. It’s not exactly lightweight, it’s a memory and CPU hog. Keep in mind that the kind of machine that runs OpenWRT might only have 32 or even 16 MB of RAM to work with.

      Also, PHP is not the first language that comes to mind when doing data processing and/or functional programming. You can but it doesn’t lend itself well to it.

      • @[email protected]
        link
        fedilink
        111 months ago

        Yeah, it’s really flexible when it comes to arrays and string processing. Super easy to work with, too.