我有一些产生颜色的脚本,我需要摆脱这个.
#!/bin/bash
exec > >(tee log) # redirect the output to a file but keep it on stdout
exec 2>&1
./somescript
Run Code Online (Sandbox Code Playgroud)
输出是(在日志文件中):
java (pid 12321) is running...@[60G[@[0;32m OK @[0;39m]
Run Code Online (Sandbox Code Playgroud)
我不知道怎么把ESC字符放在这里,所以我把@
它放在了它的位置.
我将脚本更改为:
#!/bin/bash
exec > >(tee log) # redirect the output to a file but keep it on stdout
exec 2>&1
./somescript | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
Run Code Online (Sandbox Code Playgroud)
但现在它给了我(在日志文件中):
java (pid 12321) is running...@[60G[ OK ]
Run Code Online (Sandbox Code Playgroud)
我怎么能删除这个' @[60G
?
也许有一种方法可以完全禁用整个脚本的着色?
有没有办法窥探 Golang 中的方法?
例如,假设我有
type Object struct {
A int
B string
C *interface{}
}
func (o *Object) Something(val interface{}) {
o.A = 102
// some other business logic under test
o.SomethingElse(o.C, val)
}
//...
func (o *Object) Process(val interface{}) interface{} {
// some business logic
return 43 // or something else. no me importa ya
}
//...
func (o *Object) SomethingElse(iPtr *interface{}, val interface{}) {
processedVal := o.Process(val)
if iPtr == nil {
iPtr = new(interface{})
}
*iPtr = …
Run Code Online (Sandbox Code Playgroud)