linux - 使用 linux 脚本命令

标签 linux bash shell

script 命令执行并记录日志。

( http://www.computerhope.com/unix/uscript.htm )

( http://linuxers.org/article/script-command-line-tool-recordsave-your-terminal-activity )

我使用 script 命令来保存命令和那些输出。

每当使用“脚本”时,我都会输入如下命令。

$ script result.log
Script started, file is result.log
$ date
$ ls -la.
$ exit

有时我想在 shell 脚本中使用这些命令。

所以我像下面一样跑。

$ script -c test.sh result.log

但 result.log 只有输出,不包含命令本身。 我希望 result.log 包含命令和输出。

我该怎么做?

谢谢

最佳答案

如果您使用 sh -x 运行您的脚本,它将打印命令或添加 将 -x 设置为您的脚本。

script -c "sh -x ./test.sh" reult.log

示例输出:

+ date
Tue Dec 23 09:52:22 CET 2014
+ ls -la

关于linux - 使用 linux 脚本命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616840/

相关文章:

BASH 命令提示符 : add characters behind command

bash - "correct"的最简单方法是意外使用 mv 而不是 hg mv?

bash - 环境变量不在父 shell 中持久化

java - 为 jar 应用程序创建启动器

linux - 如何在不离开当前 shell 的情况下在当前 shell 中间脚本中设置 sudo?

python - PySide2 找不到 Qt_5.15

linux - 系统调用导致Segmentation Fault

linux - Bash变量扩展不能与时间命令结合使用

shell - 从 Windows 命令行和 Linux shell 复制彩色文本

linux - 加载 *.jpg 时 cvLoadImage() 失败