From e0a71f8998e065f300d28c1a02f6a44c66a0adbe Mon Sep 17 00:00:00 2001 From: jet2tlf Date: Fri, 31 May 2024 01:15:51 -0300 Subject: pass 7st stage --- cmd/myshell/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/myshell/main.go b/cmd/myshell/main.go index d196e7c..4aa8a6d 100644 --- a/cmd/myshell/main.go +++ b/cmd/myshell/main.go @@ -8,6 +8,8 @@ import ( "strings" ) +var KnowCommands = map[string]int{"exit": 0, "echo": 1, "type": 2} + func main() { stdin := bufio.NewReader(os.Stdin) for { @@ -36,6 +38,16 @@ func main() { case "exit", "echo", "type": fmt.Printf("%s is a shell builtin\n", command[1]) default: + env := os.Getenv("PATH") + paths := strings.Split(env, ":") + + for _, path := range paths { + exec := path + "/" + command[1] + + if _, err := os.Stat(exec); err == nil { + fmt.Printf("%s is %s\n", command[1], exec) + } + } fmt.Printf("%s not found\n", command[1]) } default: -- cgit v1.2.3