dtluna 1 month ago
parent
commit
73e7ba9c1c
2 changed files with 25 additions and 0 deletions
  1. 1
    0
      README.md
  2. 24
    0
      echo/echo.go

+ 1
- 0
README.md View File

@@ -13,3 +13,4 @@ Implemeted utilities:
13 13
  * `yes`
14 14
  * `dirname`
15 15
  * `basename`
16
+ * `echo`

+ 24
- 0
echo/echo.go View File

@@ -0,0 +1,24 @@
1
+package main
2
+
3
+import (
4
+	"flag"
5
+	"fmt"
6
+	"os"
7
+	s "strings"
8
+)
9
+
10
+var noNewline = flag.Bool("n", false, "Do not print the terminating newline.")
11
+
12
+func echo(strings []string, noNewline bool) {
13
+	str := s.Join(strings, " ")
14
+	if noNewline {
15
+		fmt.Print(str)
16
+	} else {
17
+		fmt.Println(str)
18
+	}
19
+}
20
+
21
+func main() {
22
+	flag.Parse()
23
+	echo(os.Args[1:], *noNewline)
24
+}

Loading…
Cancel
Save