diff --git a/README.md b/README.md index 547467a..f22fad2 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,4 @@ Implemeted utilities: * `yes` * `dirname` * `basename` + * `echo` diff --git a/echo/echo.go b/echo/echo.go new file mode 100644 index 0000000..e6afff5 --- /dev/null +++ b/echo/echo.go @@ -0,0 +1,24 @@ +package main + +import ( + "flag" + "fmt" + "os" + s "strings" +) + +var noNewline = flag.Bool("n", false, "Do not print the terminating newline.") + +func echo(strings []string, noNewline bool) { + str := s.Join(strings, " ") + if noNewline { + fmt.Print(str) + } else { + fmt.Println(str) + } +} + +func main() { + flag.Parse() + echo(os.Args[1:], *noNewline) +}