tl;dr: I agree with the Go folks: past about 10 lines, write a program. But not everybody will agree, as I learned with u-root. Many people love shell programming. I never have.
u-root is a set of Go programs deployed on a couple million data center systems at many companies, including Google.
u-root originally used a compile-on-demand model: type a command name, if it's not in /ubin, it gets built. This was fast, in early Go, typically 250 ms or so. And, in the early days of Go, the Go toolchain, u-root, and all support source easily fit in a 16M SPI part.
The original scripting language for u-root was Go.
There were two commands for this: script and builtin. script would run Go fragments; builtin would take supplied commands and build a custom shell with those built in. Each took 250ms to run.
script took what we called a 'Go fragment', wrapped it with boiler plate, compiled it, and ran it.
e.g.
script fmt.Printf("hi\n")
would build the program and run that code.
So you could, e.g,, do math:
script fmt.Printf("%d\n", 6*7)
It could get complex: to see things about interfaces:
script 'ifaces, _ := net.Interfaces()
for _, v := range ifaces {
addrs, _ := v.Addrs()
Printf("%v has %v", v, addrs)
}'
you'd get:
ip: {1 1500 lo up|loopback} has [
127.0.0.1/8 ::1/128]
ip: {5 1500 eth0 fa:42:2c:d4:0e:01 up|broadcast} has [
172.17.0.2/16 fe80::f842:2cff:fed4:e01/64]
The second command was called builtin. It did not work as other shells do: it built a new shell for you. So, you type:
bulitin hi fmt.Printf("hi") there fmt.Printf("there\n")
builtin would convert the Go fragments to functions callable in the u-root shell, build a private name space (on Linux or Plan 9 anyway), rebuild the shell with those new functions, and at that point:
you type
hi
in the shell, and it types
hi
back. This was built in to your private shell in your private name space. Once you left the shell, it was gone.
Again, this process of creating and starting the new shell always took about 250 ms (in Go 1.2 that is).
I learned a lesson: people love their shell scripting languages. Nobody wanted to script with Go. It made me sad, but that's how it Go-es.
ron
p.s. the 'script' command is still available as an experimental u-root command. Source mode is now independent:
github.com/u-root/sourcery