This is a Go rewrite of the previous iteration writen by from Simon Willison in Bash.
System wide
go install github.com/bitfield/script/cmd/goscript@latestAs a module tool
go get -tool github.com/bitfield/script/cmd/goscript@latestIf you ever use multiple arguments for goscript from shebang, you can use
env command with -S flag. It splits the argument into separate strings.
It's because shebang recognizes only two positions:
#!first second, stil part of second
leading to: first "second, stil part of second", using env command like
this:
#!/usr/bin/env -S cmd -foo -baryou run cmd "-foo" "-bar" with two arguments.
Run as a file,
#!goscript -i=fmt,os
fmt.Println(os.Getwd())
script.
File("/etc/passwd").
Stdout()from your shell,
cat file.txt | goscript -c 'script.Stdin().Column(1).Freq().First(10).Stdout()'or as a go tool.
Define it in your go.mod manually,
//go.mod
module your.module
go 1.23
tool (
github.com/bitfield/script/cmd/goscript
)
or install it by.
go get -tool github.com/bitfield/script/cmd/goscript@latestUse by
go tool goscriptor as part of your project flow.
//go:generate go tool goscript