diff options
| -rw-r--r-- | cmd/myshell/main.go | 12 |
1 files changed, 12 insertions, 0 deletions
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: |