diff --git a/go.mod b/go.mod index f596bf5..cb07ee6 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module gosh go 1.21.5 require ( + github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/fatih/color v1.18.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index 85e5e14..05fbbf4 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= diff --git a/main.go b/main.go index 6fd923f..431f984 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" + "github.com/anmitsu/go-shlex" "github.com/chzyer/readline" "github.com/fatih/color" ) @@ -106,7 +107,12 @@ func gosh_process_input(sh *types.Shell, input string) { for _, cmdStr := range commands { cmdStr = strings.TrimSpace(cmdStr) - parts := strings.Fields(cmdStr) + parts, err := shlex.Split(cmdStr, false) + + if err != nil { + fmt.Println(err) + } + if len(parts) == 0 { continue } @@ -157,7 +163,7 @@ func gosh_process_input(sh *types.Shell, input string) { comd := exec.Command(parts[0], parts[1:]...) - out, err := comd.Output() + out, err := comd.CombinedOutput() if err != nil { fmt.Print("Error: ")