bb/newnix/echo/main.go

29 lines
685 B
Go
Raw Normal View History

/* Simple 'echo' implementation. */
package main
import (
2019-09-26 03:25:23 +03:00
"flag"
"fmt"
"strings"
)
func main() {
2019-09-26 03:25:23 +03:00
newLineFlagPtr := flag.Bool("n", false,
"Don't add new line character('-N' is lower priority).")
newLineStrPtr := flag.String("N", "\n", "Use this instead new line character.")
joinStrsFlagPtr := flag.Bool("j", false, "Join strings('-J' is lower priority).")
joinStrPtr := flag.String("J", " ", "Use instead of space as separator.")
flag.Parse()
if *newLineFlagPtr {
*newLineStrPtr = ""
}
if *joinStrsFlagPtr {
*joinStrPtr = ""
}
2019-09-26 03:25:23 +03:00
fmt.Printf("%s%s",
2019-09-26 03:25:23 +03:00
strings.Join(flag.Args(), *joinStrPtr),
*newLineStrPtr,)
}