-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no shell call on single command exec on *nix
Instead of always using `sh -c` to run command lines on *nix check if it is a single command (no spaces) and, if so, run that command directly. This will give users on systems without 'sh' a way to run their commands. Fixes #1508
- Loading branch information
Showing
3 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package manager | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func prepCommand(command string) ([]string, error) { | ||
if len(command) == 0 { | ||
switch len(strings.Fields(command)) { | ||
case 0: | ||
return []string{}, nil | ||
case 1: | ||
return []string{command}, nil | ||
} | ||
|
||
// default to 'sh' on path, else try a couple common absolute paths | ||
shell := "sh" | ||
if _, err := exec.LookPath(shell); err != nil { | ||
for _, sh := range []string{"/bin/sh", "/usr/bin/sh"} { | ||
if sh, err := exec.LookPath(sh); err == nil { | ||
shell = sh | ||
break | ||
} | ||
} | ||
} | ||
if shell == "" { | ||
return []string{}, exec.ErrNotFound | ||
} | ||
|
||
cmd := []string{"sh", "-c", command} | ||
cmd := []string{shell, "-c", command} | ||
return cmd, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters