echo: "\n" option implemented.

This commit is contained in:
jienfak 2020-01-07 06:22:16 +05:00
parent 1aa0c5d75a
commit 378ca66cd0

View file

@ -7,15 +7,18 @@ import (
) )
func Run(args []string) int { func Run(args []string) int {
var nflag bool
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError) flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.")
flagSet.Parse(args[1:]) flagSet.Parse(args[1:])
args = args[1:] args = flagSet.Args()
status := 0
l := len(args) - 1 l := len(args) - 1
for i, s := range args { for i, s := range args {
fmt.Print(s) fmt.Print(s)
if i!=l { fmt.Print(" ") } if i!=l { fmt.Print(" ") }
} }
if !nflag {
fmt.Print("\n") fmt.Print("\n")
return status }
return 0
} }