Permalink
Browse files

Created command: echo

  • Loading branch information...
1 parent eb48910 commit 13304ed19d9e4b5c7027e028a89316a697e5ce4f @jdparent committed Dec 19, 2010
Showing with 59 additions and 0 deletions.
  1. +9 −0 echo/Makefile
  2. +18 −0 echo/echo.1
  3. +32 −0 echo/echo.go
View
@@ -0,0 +1,9 @@
+# echo - print arguments
+
+TARG = echo
+
+include ../std.mk
+
+pre-uninstall:
+
+post-install:
View
@@ -0,0 +1,18 @@
+.TH ECHO 1
+.SH NAME
+echo \- print arguments
+.SH SYNOPSIS
+.B echo
+[
+.B -n
+]
+[
+.I arg ...
+]
+.SH DESCRIPTION
+.I Echo
+writes its arguments separated by blanks and terminated by
+a newline on the standard output.
+Option
+.B -n
+suppresses the newline.
View
@@ -0,0 +1,32 @@
+// echo - print arguments
+//
+// Code is pretty much line for line with the golang.org website's example app.
+// Not a whole lot can be changed to get a more simple implementation.
+package main
+
+import (
+ "os"
+ "flag"
+)
+
+var suppressNewline = flag.Bool("n", false, "Suppress final newline")
+
+const (
+ Space = " "
+ Newline = "\n"
+)
+
+func main() {
+ flag.Parse()
+ var s string = ""
+ for i := 0; i < flag.NArg(); i++ {
+ if i > 0 {
+ s += Space
+ }
+ s += flag.Arg(i)
+ }
+ if !*suppressNewline {
+ s += Newline
+ }
+ os.Stdout.WriteString(s)
+}

0 comments on commit 13304ed

Please sign in to comment.