Skip to content

Commit 28e4fdf

Browse files
authored
Merge pull request #37 from mattn/fix-36
Fix #36
2 parents d25c5ef + dde3807 commit 28e4fdf

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

shellwords_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ func TestShellRun(t *testing.T) {
8585
}
8686
}
8787

88+
func TestShellRunNoEnv(t *testing.T) {
89+
old := os.Getenv("SHELL")
90+
defer os.Setenv("SHELL", old)
91+
os.Unsetenv("SHELL")
92+
93+
dir, err := os.Getwd()
94+
if err != nil {
95+
t.Fatal(err)
96+
}
97+
98+
pwd, err := shellRun("pwd", "")
99+
if err != nil {
100+
t.Fatal(err)
101+
}
102+
103+
pwd2, err := shellRun("pwd", path.Join(dir, "/_example"))
104+
if err != nil {
105+
t.Fatal(err)
106+
}
107+
108+
if pwd == pwd2 {
109+
t.Fatal("`pwd` should be changed")
110+
}
111+
}
112+
88113
func TestBacktick(t *testing.T) {
89114
goversion, err := shellRun("go version", "")
90115
if err != nil {

util_go15.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

util_posix.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows,go1.6
1+
// +build !windows
22

33
package shellwords
44

@@ -10,7 +10,10 @@ import (
1010
)
1111

1212
func shellRun(line, dir string) (string, error) {
13-
shell := os.Getenv("SHELL")
13+
var shell string
14+
if shell = os.Getenv("SHELL"); shell == "" {
15+
shell = "/bin/sh"
16+
}
1417
cmd := exec.Command(shell, "-c", line)
1518
if dir != "" {
1619
cmd.Dir = dir

util_windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build windows,go1.6
1+
// +build windows
22

33
package shellwords
44

@@ -10,7 +10,10 @@ import (
1010
)
1111

1212
func shellRun(line, dir string) (string, error) {
13-
shell := os.Getenv("COMSPEC")
13+
var shell string
14+
if shell = os.Getenv("COMSPEC"); shell == "" {
15+
shell = "cmd"
16+
}
1417
cmd := exec.Command(shell, "/c", line)
1518
if dir != "" {
1619
cmd.Dir = dir

0 commit comments

Comments
 (0)