我有一些产生颜色的脚本,我需要摆脱这个.
#!/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?
也许有一种方法可以完全禁用整个脚本的着色?