2019-09-24 20:19:01 +03:00
|
|
|
/* Simple 'echo' implementation. */
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-09-26 03:25:23 +03:00
|
|
|
"flag"
|
2019-09-24 20:19:01 +03:00
|
|
|
"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.")
|
2019-09-26 04:21:03 +03:00
|
|
|
backslashSeqFlagPtr := flag.Bool("e", false, "Interpret backslash special terminal characters.")
|
2019-09-26 03:25:23 +03:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *newLineFlagPtr {
|
|
|
|
*newLineStrPtr = ""
|
|
|
|
}
|
|
|
|
if *joinStrsFlagPtr {
|
|
|
|
*joinStrPtr = ""
|
2019-09-24 20:19:01 +03:00
|
|
|
}
|
2019-09-26 03:25:23 +03:00
|
|
|
|
2019-09-26 04:21:03 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 20:19:01 +03:00
|
|
|
fmt.Printf("%s%s",
|
2019-09-26 04:21:03 +03:00
|
|
|
printStr,
|
|
|
|
*newLineStrPtr,)
|
2019-09-24 20:19:01 +03:00
|
|
|
}
|