go version)?$ go version go version go1.14.7 linux/amd64
Yes
go env)?go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/janisz/.cache/go-build"
GOENV="/home/janisz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/janisz/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/6274"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/6274/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/janisz/go/src/github.com/dcos/dcos-core-cli/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build069442779=/tmp/go-build -gno-record-gcc-switches"
package main
import (
"fmt"
"os/exec"
)
func main() {
command := exec.Command("echo", "OK")
command.Env = append(command.Env, "X=1", "Y=2")
fmt.Println(command.String())
}
https://play.golang.org/p/HTmQGJ12Xhp
X=1 Y=2 /bin/echo OK
/bin/echo OK
It this is accepted I'll be happy to provide a patch.
Refs: https://github.com/golang/go/issues/30638
The Env field is the complete environment to pass to the child process, and is often created by appending to os.Environ(), so that existing environment variables are preserved. In that case the output of the String method might be quite long. My shell has 61 environment variables. I'm not sure that is useful default behavior.
Based on the discussion above, this seems like a likely decline.
(The noise is much larger than the signal.)
It would probably also break existing uses.
No change in consensus, so declined.
Most helpful comment
The
Envfield is the complete environment to pass to the child process, and is often created by appending toos.Environ(), so that existing environment variables are preserved. In that case the output of theStringmethod might be quite long. My shell has 61 environment variables. I'm not sure that is useful default behavior.