]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: Plan 9 compatible "env" output
authorLucio De Re <lucio.dere@gmail.com>
Mon, 24 Feb 2014 18:48:06 +0000 (19:48 +0100)
committerDavid du Colombier <0intro@gmail.com>
Mon, 24 Feb 2014 18:48:06 +0000 (19:48 +0100)
Fixes the output of go env so that variables can be set
more accurately when using Plan 9's rc shell. Specifically,
GOPATH may have multiple components and the current
representation is plain wrong. In practice, we probably
ought to change os. Getenv to produce the right result, but
that requires considerably more thought.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/66600043

src/cmd/go/env.go

index 05774c2cf5dee537d6133b8329a016518b9676a5..26d37df4f9b7766b02b0752dfcea95f9ff3dc28a 100644 (file)
@@ -91,7 +91,19 @@ func runEnv(cmd *Command, args []string) {
                        default:
                                fmt.Printf("%s=\"%s\"\n", e.name, e.value)
                        case "plan9":
-                               fmt.Printf("%s='%s'\n", e.name, strings.Replace(e.value, "'", "''", -1))
+                               if strings.IndexByte(e.value, '\x00') < 0 {
+                                       fmt.Printf("%s='%s'\n", e.name, strings.Replace(e.value, "'", "''", -1))
+                               } else {
+                                       v := strings.Split(e.value, "\x00")
+                                       fmt.Printf("%s=(", e.name)
+                                       for x, s := range v {
+                                               if x > 0 {
+                                                       fmt.Printf(" ")
+                                               }
+                                               fmt.Printf("%s", s)
+                                       }
+                                       fmt.Printf(")\n")
+                               }
                        case "windows":
                                fmt.Printf("set %s=%s\n", e.name, e.value)
                        }