I’m on Stage #IZ3.
I passed the stage but I don’t think I’m doing it with best pracices.
And here’s a snippet of my code:
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
for {
fmt.Fprint(os.Stdout, "$ ")
input, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
fmt.Fprint(os.Stderr, "ERROR: ", err)
return
}
input = strings.TrimSpace(input) // to remove the \n
if input == "exit 0" {
return
}
words := strings.Fields(input)
if words[0] == "echo" {
for i := 1; i < len(words); i++ {
fmt.Fprint(os.Stdout, words[i]+" ")
}
fmt.Fprint(os.Stdout, "\n")
} else {
fmt.Fprint(os.Stdout, input+": command not found\n")
}
}
}
am I doing well or there’s a better way?