func do(command cmd) (string, error) {
	expanded := os.Expand(command.Line, os.Getenv)
	var out string
	if command.echo {
		out = expanded
	} else {
		split := strings.Split(expanded, " ")
		cmd := exec.Command(split[0], split[1:]...)
		bout, err := cmd.Output()
		if err != nil {
			return "", err
		}
		out = string(bout)
	}
	val := strings.TrimSpace(out)
	err := os.Setenv(command.Var, val)
	if err != nil {
		return "", err
	}
	return val, nil
}
do the cmd by expanding in the shell and running (as needed)
package main
import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"go/format"
	"io"
	"os"
	"os/exec"
	"path"
	"strings"
	"text/template"
)
const (
	templatePrelude = ` 
package {{.GOPKG}}
const (
	MustRunBuildConstants = 0
`
	templatePostlude = ")"
)
type cmdReader struct {
	scanner   *bufio.Scanner
	separator string
}
func newCmdReader(r io.Reader, sep string) *cmdReader {
	return &cmdReader{scanner: bufio.NewScanner(r), separator: sep}
}
func (r cmdReader) read() ([]cmd, error) {
	var cmds []cmd
	for r.scanner.Scan() {
		k, v, err := lineSplit(r.scanner.Text(), r.separator)
		if err != nil {
			continue
		}
		c := parseCmd(k, v)
		cmds = append(cmds, c)
	}
	return cmds, nil
}
func lineSplit(line, sep string) (string, string, error) {
	splits := strings.Split(line, sep)
	if len(splits) < 2 {
		return "", "", errors.New("invalid line")
	}
	rest := strings.TrimSpace(strings.Join(splits[1:], " "))
	return splits[0], rest, nil
}
func parseCmd(key, val string) cmd {
	return cmd{
		Var:  strings.TrimSpace(key),
		Line: val,
		echo: isEnvVar(val),
	}
}
func isEnvVar(s string) bool {
	return strings.HasPrefix(s, "$")
}
type cmd struct {
	Var  string
	Line string
	echo bool  
}
func cmdRead(cmdfile string) ([]cmd, error) {
	f, err := os.Open(cmdfile)
	if err != nil {
		return []cmd{}, err
	}
	defer f.Close()
	cr := newCmdReader(f, "=")
	return cr.read()
}
func envTemplate(ins []cmd) string {
	var s string
	for _, in := range ins {
		s = s + " " + in.Var + " = \"{{." + in.Var + "}}\"\n"
	}
	return s
}