Skip to content

Commit 7d0fb03

Browse files
authored
Improved Shell Detection (#1658)
Use the SHELL environment variable instead of the /etc/passwd file for determining the shell on Linux.
1 parent b59e9e9 commit 7d0fb03

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

cmd/wsh/cmd/wshcmd-shell-unix.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package cmd
77

88
import (
9-
"bufio"
109
"os"
11-
"os/user"
1210
"runtime"
1311
"strings"
1412

@@ -33,30 +31,10 @@ func shellCmdInner() string {
3331
if runtime.GOOS == "darwin" {
3432
return shellutil.GetMacUserShell() + "\n"
3533
}
36-
user, err := user.Current()
37-
if err != nil {
38-
return "/bin/bash\n"
39-
}
4034

41-
passwd, err := os.Open("/etc/passwd")
42-
if err != nil {
35+
shell := os.Getenv("SHELL")
36+
if shell == "" {
4337
return "/bin/bash\n"
4438
}
45-
46-
scanner := bufio.NewScanner(passwd)
47-
for scanner.Scan() {
48-
line := scanner.Text()
49-
line = strings.TrimSpace(line)
50-
parts := strings.Split(line, ":")
51-
52-
if len(parts) != 7 {
53-
continue
54-
}
55-
56-
if parts[0] == user.Username {
57-
return parts[6] + "\n"
58-
}
59-
}
60-
// none found
61-
return "/bin/bash\n"
39+
return strings.TrimSpace(shell) + "\n"
6240
}

pkg/util/utilfn/utilfn.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,9 @@ func FilterValidArch(arch string) (string, error) {
974974
formatted := strings.TrimSpace(strings.ToLower(arch))
975975
switch formatted {
976976
case "amd64":
977+
return "x64", nil
977978
case "x86_64":
979+
return "x64", nil
978980
case "x64":
979981
return "x64", nil
980982
case "arm64":

0 commit comments

Comments
 (0)