我正在尝试使用
script命令来记录交互式shell会话,以便我可以使用它来准备文档.
原文链接:https://www.f2er.com/bash/384595.html根据手册页:
Script places everything in the log file,including lineFeeds and
backspaces. This is not what the naive user expects.
我是天真的用户(通常不会在手册页中大喊大叫,这非常令人兴奋!),我想处理输出,以便删除退格,换行和删除的字符等.
例如,我运行一个脚本会话:
stew:~> script -f scriptsession.log Script started,file is scriptsession.log stew:~> date Mon Aug 22 15:00:37 EDT 2011 stew:~> #extra chars: that stew:~> exit exit Script done,file is scriptsession.log
然后我用cat来读取会话日志:
stew:~> cat scriptsession.log Script started on Mon 22 Aug 2011 03:00:35 PM EDT stew:~> date Mon Aug 22 15:00:37 EDT 2011 stew:~> #extra chars: that stew:~> exit exit Script done on Mon 22 Aug 2011 03:01:01 PM EDT
但是当我少用时,我会看到使用cat看不见的不需要的字符的证据:
stew:~> less scriptsession.log Script started on Mon 22 Aug 2011 03:00:35 PM EDT stew:~> date Mon Aug 22 15:00:37 EDT 2011 stew:~> #extra chars: thiESC[ESC[ESC[ESC[Kthat stew:~> exit exit Script done on Mon 22 Aug 2011 03:01:01 PM EDT scriptsession.log lines 1-8/8 (END)
当我使用cat时,我明白它不会删除不可见的字符,它只是不会明显地表示它们,就像少了 – 所以如果我将cat输出管道传输到文件,它仍然有不需要的字符.