summaryrefslogtreecommitdiff
path: root/test/goecho/goecho.go
blob: 1c8d2f586fe52c73a85e3b3be0b7c4339c68f9f0 (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 (
	"fmt"
	"os"
	"strconv"
	"time"
)

func main() {
	args := os.Args[1:]
	exitCode := 0

	for i := 0; i < len(args); i++ {
		fmt.Fprintln(os.Stdout, args[i])
		fmt.Fprintln(os.Stderr, args[i])
	}

	if len(args) > 1 {
		num, _ := strconv.Atoi(args[1])
		if args[0] == "exitcode" {
			exitCode = num
		}
		if args[0] == "sleep" {
			time.Sleep(time.Duration(num) * time.Second)
		}
	}
	os.Exit(exitCode)
}