aboutsummaryrefslogtreecommitdiff
path: root/cmd/myshell/main.go
blob: beac132feb10855d05f5c7c75ba378bdcd092dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	stdin := bufio.NewReader(os.Stdin)
	for {
		fmt.Fprint(os.Stdout, "$ ")

		in, err := stdin.ReadString('\n')
		if err != nil {
			fmt.Println(err.Error())
		}

		commands := strings.Split(in, " ")

		switch in {
			case commnds[0] == "exit":
				os.Exit(commands[1])
		}

		fmt.Printf("%s: command not found\n", strings.TrimRight(in, "\n"))
	}
}