From 2ce694b77a02be7065f655863d268e12938d3e13 Mon Sep 17 00:00:00 2001 From: k1574 Date: Wed, 6 Oct 2021 04:15:20 +0500 Subject: [PATCH] echo: added delimiter option. --- echo/echo.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/echo/echo.go b/echo/echo.go index d9e2229..ea135cc 100644 --- a/echo/echo.go +++ b/echo/echo.go @@ -6,19 +6,26 @@ import ( "flag" ) +var( + del string + eol = "\n" +) + func Run(args []string) int { var nflag bool flagSet := flag.NewFlagSet(args[0], flag.ExitOnError) flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.") + flagSet.StringVar(&del, "d", " ", "Delimiter of arguments") flagSet.Parse(args[1:]) args = flagSet.Args() l := len(args) - 1 for i, s := range args { fmt.Print(s) - if i!=l { fmt.Print(" ") } + if i!=l { fmt.Print(del) } } if !nflag { - fmt.Print("\n") + fmt.Print(eol) } + return 0 }