package linux import ( "errors" "fmt" "os/exec" ) func (cmd *LinuxCommand) doesCommandExist(command string) (bool, error) { shellCmd := exec.Command(cmd.Options.Shell, "-c", fmt.Sprintf("command -v %s", command)) if err := shellCmd.Start(); err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { if exitErr.ExitCode() == 1 { return false, nil } else { return false, ErrRunningCmd } } } if err := shellCmd.Wait(); err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { if exitErr.ExitCode() == 1 { return false, nil } else { return false, ErrRunningCmd } } } return true, nil }