aboutsummaryrefslogtreecommitdiff
path: root/cmd/myshell/main.go
diff options
context:
space:
mode:
authorjet2tlf <jet2tlf@gmail.com>2024-05-31 03:34:47 +0000
committerjet2tlf <jet2tlf@gmail.com>2024-05-31 03:34:47 +0000
commit8c6b68001eea6d24373e7ad45e72865cc15bcdbb (patch)
tree1680b370ef4a37626cd5c3147beefe4445e71119 /cmd/myshell/main.go
parent9dc8f49cf8651c7976624417c427bc6d4bcc5048 (diff)
downloadshell-go-8c6b68001eea6d24373e7ad45e72865cc15bcdbb.tar.gz
shell-go-8c6b68001eea6d24373e7ad45e72865cc15bcdbb.zip
pass 6st stage
Diffstat (limited to 'cmd/myshell/main.go')
-rw-r--r--cmd/myshell/main.go17
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])
}
}
}