script package - github.com/bitfield/script - Go Packages

submited by
Style Pass
2024-09-05 14:00:02

script is a Go library for doing the kind of tasks that shell scripts are good at: reading files, executing subprocesses, counting lines, matching strings, and so on.

Why shouldn't it be as easy to write system administration programs in Go as it is in a typical shell? script aims to make it just that easy.

This is one absolutely superb API design. Taking inspiration from shell pipes and turning it into a Go library with syntax this clean is really impressive. —Simon Willison

If you're already familiar with shell scripting and the Unix toolset, here is a rough guide to the equivalent script operation for each listed Unix command.

But what if, instead of reading a specific file, we want to simply pipe input into this program, and have it output only matching lines (like grep)?

That was almost too easy! So let's pass in a list of files on the command line, and have our program read them all in sequence and output the matching lines:

Leave a Comment