echo: "\n" option implemented.
This commit is contained in:
parent
1aa0c5d75a
commit
378ca66cd0
1 changed files with 7 additions and 4 deletions
11
echo/echo.go
11
echo/echo.go
|
@ -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(" ") }
|
||||||
}
|
}
|
||||||
fmt.Print("\n")
|
if !nflag {
|
||||||
return status
|
fmt.Print("\n")
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue