我曾多次看到使用 script 命令的 bash 脚本。我使用 man script 并向我展示了script - make typescript of terminal session
之后我用谷歌搜索了一下,但没有找到任何有用的东西。我有两个问题。它们是:
1-命令有什么用script
?
2-为什么命令script -qc "exit 1"
返回退出代码 0?
答案1
脚本- 制作终端会话的打字稿
script 将终端上显示的所有内容打印成一份脚本。对于需要交互式会话的硬拷贝记录作为作业证明的学生来说,这很有用,因为稍后可以使用 lpr(1) 打印出脚本文件。
Atypescript
是“已输入的文本或文档的副本”。因此,该命令基本上记录了会话。
答案2
1-脚本命令有什么用?
有时,命令在与其一起使用的其他命令的上下文中更有意义。如果您查看SEE ALSO
手册页的部分,您会看到:
SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1), scriptlive(1),
检查scriptreplay
:
NAME
scriptreplay - play back typescripts, using timing information
SYNOPSIS
scriptreplay [options] [-t] timingfile [typescript [divisor]]
DESCRIPTION
This program replays a typescript, using timing information to ensure
that output happens in the same rhythm as it originally appeared when
the script was recorded.
The replay simply displays the information again; the programs that
were run when the typescript was being recorded are not run again.
检查scriptlive
:
NAME
scriptlive - re-run session typescripts, using timing information
SYNOPSIS
scriptlive [options] [-t] timingfile [-I|-B] typescript
DESCRIPTION
This program re-runs a typescript, using stdin typescript and timing
information to ensure that input happens in the same rhythm as it orig‐
inally appeared when the script was recorded.
The session is executed in a newly created pseudoterminal with the
user's $SHELL (or defaults to /bin/bash).
因此,script
您可以使用录音来重播会话(如视频但带有文本),或重新执行它。如果您想在途易并可选择在相同时间重复您的动作。
2-为什么命令脚本 -qc“exit 1”返回退出代码 0?
它的主要工作是记录,因此当它成功记录时返回成功是有意义的,即使它记录失败。但是,如果您希望传递返回值,也可以这样做-e
:--return
-e, --return
Return the exit status of the child process. Uses the same for‐
mat as bash termination on signal termination (i.e., exit status
is 128 + the signal number). The exit status of the child
process is always stored in the type script file too.