Skip to content

Commit 646fe23

Browse files
authored
add links to readme (#234)
1 parent 6006cd0 commit 646fe23

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

README.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import "github.com/bitfield/script"
99
```
1010

11-
[![Magical gopher logo](img/magic.png)](https://bitfieldconsulting.com/golang/scripting)
11+
[![Magical gopher logo](img/magic.png)](https://bitfieldconsulting.com/subscribe)
12+
13+
[Subscribe to learn Go with me!](https://bitfieldconsulting.com/subscribe)
1214

1315
# What is `script`?
1416

@@ -21,41 +23,11 @@ Shell scripts often compose a sequence of operations on a stream of data (a _pip
2123
> *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.*\
2224
> [Simon Willison](https://news.ycombinator.com/item?id=30649524)
2325
24-
Read more: [Scripting with Go](https://bitfieldconsulting.com/golang/scripting)
25-
26-
# Quick start: Unix equivalents
27-
28-
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.
26+
# Quick start
2927

30-
| Unix / shell | `script` equivalent |
31-
| ------------------ | ------------------- |
32-
| (any program name) | [`Exec`](https://pkg.go.dev/github.com/bitfield/script#Exec) |
33-
| `[ -f FILE ]` | [`IfExists`](https://pkg.go.dev/github.com/bitfield/script#IfExists) |
34-
| `>` | [`WriteFile`](https://pkg.go.dev/github.com/bitfield/script#Pipe.WriteFile) |
35-
| `>>` | [`AppendFile`](https://pkg.go.dev/github.com/bitfield/script#Pipe.AppendFile) |
36-
| `$*` | [`Args`](https://pkg.go.dev/github.com/bitfield/script#Args) |
37-
| `base64` | [`DecodeBase64`](https://pkg.go.dev/github.com/bitfield/script#Pipe.DecodeBase64) / [`EncodeBase64`](https://pkg.go.dev/github.com/bitfield/script#Pipe.EncodeBase64) |
38-
| `basename` | [`Basename`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Basename) |
39-
| `cat` | [`File`](https://pkg.go.dev/github.com/bitfield/script#File) / [`Concat`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Concat) |
40-
| `curl` | [`Do`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Do) / [`Get`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Get) / [`Post`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Post) |
41-
| `cut` | [`Column`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Column) |
42-
| `dirname` | [`Dirname`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Dirname) |
43-
| `echo` | [`Echo`](https://pkg.go.dev/github.com/bitfield/script#Echo) |
44-
| `find` | [`FindFiles`](https://pkg.go.dev/github.com/bitfield/script#FindFiles) |
45-
| `grep` | [`Match`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Match) / [`MatchRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.MatchRegexp) |
46-
| `grep -v` | [`Reject`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Reject) / [`RejectRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.RejectRegexp) |
47-
| `head` | [`First`](https://pkg.go.dev/github.com/bitfield/script#Pipe.First) |
48-
| `jq` | [`JQ`](https://pkg.go.dev/github.com/bitfield/script#Pipe.JQ) |
49-
| `ls` | [`ListFiles`](https://pkg.go.dev/github.com/bitfield/script#ListFiles) |
50-
| `sed` | [`Replace`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Replace) / [`ReplaceRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.ReplaceRegexp) |
51-
| `sha256sum` | [`Hash`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Hash) / [`HashSums`](https://pkg.go.dev/github.com/bitfield/script#Pipe.HashSums) |
52-
| `tail` | [`Last`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Last) |
53-
| `tee` | [`Tee`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Tee) |
54-
| `uniq -c` | [`Freq`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Freq) |
55-
| `wc -l` | [`CountLines`](https://pkg.go.dev/github.com/bitfield/script#Pipe.CountLines) |
56-
| `xargs` | [`ExecForEach`](https://pkg.go.dev/github.com/bitfield/script#Pipe.ExecForEach) |
28+
Read my tutorial: [Scripting with Go](https://bitfieldconsulting.com/golang/scripting)
5729

58-
# Some examples
30+
# Examples
5931

6032
Let's see some simple examples. Suppose you want to read the contents of a file as a string:
6133

@@ -259,6 +231,38 @@ Let's try it out with some [sample data](testdata/access.log):
259231
1 90.53.111.17
260232
```
261233

234+
# Unix equivalents
235+
236+
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.
237+
238+
| Unix / shell | `script` equivalent |
239+
| ------------------ | ------------------- |
240+
| (any program name) | [`Exec`](https://pkg.go.dev/github.com/bitfield/script#Exec) |
241+
| `[ -f FILE ]` | [`IfExists`](https://pkg.go.dev/github.com/bitfield/script#IfExists) |
242+
| `>` | [`WriteFile`](https://pkg.go.dev/github.com/bitfield/script#Pipe.WriteFile) |
243+
| `>>` | [`AppendFile`](https://pkg.go.dev/github.com/bitfield/script#Pipe.AppendFile) |
244+
| `$*` | [`Args`](https://pkg.go.dev/github.com/bitfield/script#Args) |
245+
| `base64` | [`DecodeBase64`](https://pkg.go.dev/github.com/bitfield/script#Pipe.DecodeBase64) / [`EncodeBase64`](https://pkg.go.dev/github.com/bitfield/script#Pipe.EncodeBase64) |
246+
| `basename` | [`Basename`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Basename) |
247+
| `cat` | [`File`](https://pkg.go.dev/github.com/bitfield/script#File) / [`Concat`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Concat) |
248+
| `curl` | [`Do`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Do) / [`Get`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Get) / [`Post`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Post) |
249+
| `cut` | [`Column`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Column) |
250+
| `dirname` | [`Dirname`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Dirname) |
251+
| `echo` | [`Echo`](https://pkg.go.dev/github.com/bitfield/script#Echo) |
252+
| `find` | [`FindFiles`](https://pkg.go.dev/github.com/bitfield/script#FindFiles) |
253+
| `grep` | [`Match`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Match) / [`MatchRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.MatchRegexp) |
254+
| `grep -v` | [`Reject`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Reject) / [`RejectRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.RejectRegexp) |
255+
| `head` | [`First`](https://pkg.go.dev/github.com/bitfield/script#Pipe.First) |
256+
| `jq` | [`JQ`](https://pkg.go.dev/github.com/bitfield/script#Pipe.JQ) |
257+
| `ls` | [`ListFiles`](https://pkg.go.dev/github.com/bitfield/script#ListFiles) |
258+
| `sed` | [`Replace`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Replace) / [`ReplaceRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.ReplaceRegexp) |
259+
| `sha256sum` | [`Hash`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Hash) / [`HashSums`](https://pkg.go.dev/github.com/bitfield/script#Pipe.HashSums) |
260+
| `tail` | [`Last`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Last) |
261+
| `tee` | [`Tee`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Tee) |
262+
| `uniq -c` | [`Freq`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Freq) |
263+
| `wc -l` | [`CountLines`](https://pkg.go.dev/github.com/bitfield/script#Pipe.CountLines) |
264+
| `xargs` | [`ExecForEach`](https://pkg.go.dev/github.com/bitfield/script#Pipe.ExecForEach) |
265+
262266
# A `script` “interpreter”
263267

264268
One of the nice things about shell scripts is that there's no build process: the script file itself is the “executable” (in fact, it's interpreted by the shell). Simon Willison (and GPT-4) contributed this elegant `script` interpreter, written in `bash`:
@@ -399,9 +403,9 @@ See the [contributor's guide](CONTRIBUTING.md) for some helpful tips if you'd li
399403

400404
# Links
401405

406+
- [Learn Go with me](https://bitfieldconsulting.com/subscribe)
402407
- [Scripting with Go](https://bitfieldconsulting.com/posts/scripting)
403408
- [Code Club: Script](https://www.youtube.com/watch?v=6S5EqzVwpEg)
404-
- [Bitfield Consulting](https://bitfieldconsulting.com/)
405-
- [Go books by John Arundel](https://bitfieldconsulting.com/books)
409+
- [Books by John Arundel](https://bitfieldconsulting.com/books)
406410

407411
<small>Gopher image by [MariaLetta](https://github.com/MariaLetta/free-gophers-pack)</small>

0 commit comments

Comments
 (0)