Source file doc/progs/echo.go
1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "os" 9 "flag" // command line option parser 10 ) 11 12 var omitNewline = flag.Bool("n", false, "don't print final newline") 13 14 const ( 15 Space = " " 16 Newline = "\n" 17 ) 18 19 func main() { 20 flag.Parse() // Scans the arg list and sets up flags 21 var s string = "" 22 for i := 0; i < flag.NArg(); i++ { 23 if i > 0 { 24 s += Space 25 } 26 s += flag.Arg(i) 27 } 28 if !*omitNewline { 29 s += Newline 30 } 31 os.Stdout.WriteString(s) 32 }