diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/myshell/main.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/cmd/myshell/main.go b/cmd/myshell/main.go index 84f1b23..d196e7c 100644 --- a/cmd/myshell/main.go +++ b/cmd/myshell/main.go @@ -20,19 +20,26 @@ func main() { trim := strings.TrimSpace(in) - commands := strings.Split(trim, " ") + command := strings.Split(trim, " ") - switch commands[0] { + switch command[0] { case "exit": - code, err := strconv.Atoi(commands[1]) + code, err := strconv.Atoi(command[1]) if err != nil { fmt.Println(err.Error()) } os.Exit(code) case "echo": - fmt.Printf("%s\n", strings.Join(commands[1:], " ")) + fmt.Println(strings.Join(command[1:], " ")) + case "type": + switch command[1] { + case "exit", "echo", "type": + fmt.Printf("%s is a shell builtin\n", command[1]) + default: + fmt.Printf("%s not found\n", command[1]) + } default: - fmt.Printf("%s: command not found\n", commands[0]) + fmt.Printf("%s: command not found\n", command[0]) } } } |