使用一个简单的行命令设计脚本命令实用程序

时间:2011-09-07 10:03:15

标签: shell stdout stdin stderr

script实用程序的工作原理如下:

$ script
Script started, file is typescript
$ ls
2           bin         doubleline  new1        play        typescript
alok        core        filelist    output      pslist      unix
$ ps
   PID TTY      TIME CMD
 28149 pts/7    0:00 ksh.ms
$
Script done, file is typescript

typescript文件的此内容为:

$ cat typescript
Script started on Wed Sep 07 05:56:26 2011
$ ls
2           bin         doubleline  new1        play        typescript
alok        core        filelist    output      pslist      unix
$ ps
   PID TTY      TIME CMD
 28149 pts/7    0:00 ksh.ms
$

script done on Wed Sep 07 05:56:33 2011

$

我想使用其他命令和I / O重定向来复制此行为。 解决方案必须是一行命令(可能包括流水线命令)。

任何帮助都会很棒,比如有人能告诉我们如何将stdin,stdout和stderr重定向到某个文件,而所有数据仍在终端上。

1 个答案:

答案 0 :(得分:0)

$tee -a typescript | sh -i 2>&1 | tee -a typescript