From 8c6b68001eea6d24373e7ad45e72865cc15bcdbb Mon Sep 17 00:00:00 2001 From: jet2tlf Date: Fri, 31 May 2024 00:34:47 -0300 Subject: pass 6st stage --- cmd/myshell/main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'cmd/myshell/main.go') 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]) } } } -- cgit v1.2.3