From 73b6a04611f6fdffad0b288f91891a7099905de9 Mon Sep 17 00:00:00 2001 From: jienfak Date: Thu, 26 Sep 2019 06:21:03 +0500 Subject: [PATCH] newnix: echo: '-e' option added. --- newnix/echo/main.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/newnix/echo/main.go b/newnix/echo/main.go index 17b464c..94bffa4 100644 --- a/newnix/echo/main.go +++ b/newnix/echo/main.go @@ -13,6 +13,7 @@ func main() { 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.") + backslashSeqFlagPtr := flag.Bool("e", false, "Interpret backslash special terminal characters.") flag.Parse() if *newLineFlagPtr { @@ -22,7 +23,26 @@ func main() { *joinStrPtr = "" } + printStr := strings.Join(flag.Args(), *joinStrPtr) + if *backslashSeqFlagPtr { + seqs := map[string] string { + "\\\\" : "\\", + "\\a" : "\a", + "\\b" : "\b", + /*"\\c" : "\c", + "\\e" : "\e",*/ + "\\f" : "\f", + "\\n" : "\n", + "\\r" : "\r", + "\\t" : "\t", + "\\v" : "\v", + } + for k, v := range seqs { + printStr = strings.ReplaceAll(printStr, k, v) + } + } + fmt.Printf("%s%s", - strings.Join(flag.Args(), *joinStrPtr), - *newLineStrPtr,) + printStr, + *newLineStrPtr,) }