-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.go
More file actions
32 lines (29 loc) · 723 Bytes
/
echo.go
File metadata and controls
32 lines (29 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"flag"
"fmt"
"strings"
)
func (app *applets) Applet_echo(args []string) {
var set = flag.NewFlagSet(args[0], flag.ExitOnError)
var eflag = set.Bool("e", false, "disable escape sequences")
var nflag = set.Bool("n", false, `disable print \n`)
set.Parse(args[1:])
args = set.Args()
for i := range args {
if *eflag {
chars1 := []string{`\a`, `\b`, `\e`, `\f`, `\n`, `\r`, `\t`, `\v`, `\\`, `\0`}
chars2 := []byte{'\a', '\b', 27, '\f', '\n', '\r', '\t', '\v', '\\', '\\'}
for j := range chars1 {
args[i] = strings.Replace(args[i], string(chars1[j]), string(chars2[j]), -1)
}
}
if i != 0 {
fmt.Print(" ")
}
fmt.Print(args[i])
}
if !(*nflag) {
fmt.Println()
}
}