{"repo":"bitfield/script","free":true,"listed":false,"github":"https://github.com/bitfield/script","clone":"git clone https://github.com/bitfield/script.git","description":"Making it easy to write shell-like scripts in Go","language":"Go","stars":7023,"topics":["shell","cat","curl","cut","files","find","go","golang","grep","head"],"license":"MIT","category":"cli-tools","readme_excerpt":"What is script ? 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. Shell scripts often compose a sequence of operations on a stream of data (a pipeline ). This is how script works, too. 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 Quick start Read my tutorial: Scripting with Go Examples Let's see some simple examples. Suppose you want to read the contents of a file as a string: That looks straightforward enough, but suppose you now want to count the lines in that file. For something a bit more challenging, let's try counting the number of lines in the file that match the string Error : 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 )? Just for fun, let's filter all the results through some arbitrary Go function: 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: Maybe we're only interested in the first 10 matches. No problem: What's that? You want to append that output to a file instead of pr","default_branch":null,"files":null,"tree":[],"storefront":"/r/bitfield","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/bitfield/script/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}