package main

import (
	"errors"
	"fmt"
	"os"
	"os/exec"
	"strings"
)

func main() {
	out, err := exec.Command("uname", "-s").Output()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("kernel:", strings.TrimSpace(string(out)))

	// the words go to the program as they are, no shell reads them
	err = exec.Command("grep", "-q", "DEBUG", "nas.log").Run()
	var failed *exec.ExitError
	switch {
	case err == nil:
		fmt.Println("grep found DEBUG")
	case errors.As(err, &failed):
		fmt.Println("grep ended with code", failed.ExitCode())
	default:
		fmt.Println(err)
	}
}
