This is a copy of cmd/go/internal/script.
See https://pkg.go.dev/rsc.io/script and https://pkg.go.dev/rsc.io/script/scripttest. Posting it here makes it available for others to try without us committing to officially supporting it. We have been using it in the go command for many years now; the code is quite stable. Ironically, it has very few tests.
https://github.com/rogpeppe/go-internal/testscript is a port of an earlier version of the go command script language.