I’ve been using this to execute Go “scripts” in CI pipelines where Bash just doesn’t cut it. It’s an interpreter for Go. It can be used to treat Go code like a “script,” rather than a compiled application. It is also able to be imported into a Go program and used to load up Go code dynamically at run time (think “loading plugins” with Go!).
From the readme:
Yaegi is Another Elegant Go Interpreter.
It powers executable Go scripts and plugins, in embedded interpreters or interactive shells, on top of the Go runtime.
Written in pure Go, using only the standard library
Simple interpreter API: New(), Eval(), Use()
Works everywhere Go works
All Go & runtime resources accessible from script (with control)
Security: unsafe and syscall packages neither used nor exported by default
Support the latest 2 major releases of Go (Go 1.19 and Go 1.20)
Install
Go package
import "github.com/traefik/yaegi/interp"
Command-line executable
go install github.com/traefik/yaegi/cmd/yaegi@latest
Note that you can use rlwrap (install with your favorite package manager),
and alias the yaegi command in alias yaegi='rlwrap yaegi' in your ~/.bashrc, to have history and command line edition.