this post was submitted on 27 Aug 2024
113 points (94.5% liked)

Linux

47976 readers
1050 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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.

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 2 months ago

Looking through the packages available for OpenWRT I would suggest Tcl, Lua, Erlang or Scheme (the latter is available through the Chicken interpreter). Try them out, see what you like.

[–] [email protected] 1 points 2 months ago
[–] [email protected] 4 points 2 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] 4 points 2 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] 2 points 2 months ago

You could use Ansible for automation just keep in mind it needs python.

[–] [email protected] -3 points 2 months ago

Powershell is the superior choice. But if you can't even have bash you probably won't have access.

[–] [email protected] 3 points 2 months ago

You should probably check out Guile.

[–] [email protected] 12 points 2 months ago (2 children)

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] 1 points 2 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] 6 points 2 months ago

Pwsh 7.x works very well in Linux. Haven't got any snags.

[–] [email protected] 6 points 2 months ago

I've looked into this a lot actually. There see many options. I'll highlight the pros and cons of each option.

Lua: extremely lightweight, but standard library is lacking, and doesn't include stuff like map or fold. But that would be easy to fix.

Python: thicc standard library, but is not lightweight by any means. There are modifications made to be more shell like, such as xonsh

Rash: based on scheme, very much functional but if you're not used to lisp style, might take a bit to get used to it. This is actually my favorite option. It has a cli interpreter, and really pleasant to use. Cons is... Well it's not very common

You can honestly use any language. Even most compiled languages have a way to run immediately.

[–] [email protected] 4 points 2 months ago

You might enjoy lua or lune.

[–] [email protected] 8 points 2 months ago (3 children)

I still love bash. I'm able to accomplish quite a lot with it. I vote bash.

[–] [email protected] 1 points 2 months ago

Nah, gross. You need to set a bunch of global options to get sane behavior on errors.

Nushell is shaping up really really nicely, and it'll actually stop executing if something fails! Even if that happens in a pipe! And it's not super eager to convert between arrays and strings if you use the wrong cryptic rune.

[–] [email protected] 3 points 2 months ago (1 children)

Bash? On windows it's pretty much unusable even if you use cygwin. Python or Lua are the only reasonable suggestions here

[–] [email protected] 1 points 2 months ago

I just assumed the scripts would run on Linux.

[–] [email protected] 4 points 2 months ago

Also vote bash, but I don't love it..more of a tolerate.

[–] [email protected] 6 points 2 months ago* (last edited 2 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] -2 points 2 months ago

That verb doesn't work like that.

[–] [email protected] 12 points 2 months ago

another vote for Lua – lua5.4 is available for all 8 Alpine architectures, tiny installed size (120–200 kB) (and Alpine package only installs two files)

[–] [email protected] 1 points 2 months ago

Why does it need to be a scripting (by this I assume interpreted) language? For your requirements - particularly lightweight distribution - a precompiled binary seems more appropriate. Maybe look into Go, which is a pretty simple language that can be easily compiled to native binaries.

[–] [email protected] 3 points 2 months ago

posix sh + awk for manipulating data?

load more comments
view more: next ›