diff options
| author | jet2tlf <jet2tlf@gmail.com> | 2024-05-31 04:15:51 +0000 |
|---|---|---|
| committer | jet2tlf <jet2tlf@gmail.com> | 2024-05-31 04:15:51 +0000 |
| commit | e0a71f8998e065f300d28c1a02f6a44c66a0adbe (patch) | |
| tree | ee47668cb61a8fb788ee8391ed6d8185d6de8bce | |
| parent | 8c6b68001eea6d24373e7ad45e72865cc15bcdbb (diff) | |
| download | shell-go-e0a71f8998e065f300d28c1a02f6a44c66a0adbe.tar.gz shell-go-e0a71f8998e065f300d28c1a02f6a44c66a0adbe.zip | |
pass 7st stage
| -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: |