Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 将shell脚本结果输出到类似终端屏幕的文件_Linux_Bash_Shell_Unix_Ksh - Fatal编程技术网

Linux 将shell脚本结果输出到类似终端屏幕的文件

Linux 将shell脚本结果输出到类似终端屏幕的文件,linux,bash,shell,unix,ksh,Linux,Bash,Shell,Unix,Ksh,我是shell脚本的初学者,下面是我的示例脚本: #!/bin/ksh echo "start script" ls echo "end script" 我通过以下命令运行它:/runScript.ksh>outPutFile.txt 并在文件中获得输出: start script file1.txt file2.txt file3.txt end script 我只是想问一下,是否有可能在文件中有这个输出?如在终端上执行命令时所示: user@serverName:/parentPath/

我是shell脚本的初学者,下面是我的示例脚本:

#!/bin/ksh
echo "start script"
ls
echo "end script"
我通过以下命令运行它:
/runScript.ksh>outPutFile.txt

并在文件中获得输出:

start script
file1.txt
file2.txt
file3.txt
end script
我只是想问一下,是否有可能在文件中有这个输出?如在终端上执行命令时所示:

user@serverName:/parentPath/childPath/>echo "start script"
user@serverName:/parentPath/childPath/>ls
file1.txt
file2.txt
file3.txt
user@serverName:/parentPath/childPath/>echo "end script"
事先非常感谢你。我真的很感激任何帮助

Use the 'script' command. Any command issued after the 'scipt' command will be captured in the specified file (or default file typescript).

**Example:**

$ script my_output.txt
Script started, output file is my_output.txt
$ uname -r
16.1.0
$ date
Wed Mar  8 12:55:29 IST 2017
$ exit

Script done, output file is my_output.txt
$ cat my_output.txt
Script started on Wed Mar  8 12:55:19 2017
$ uname -r
16.1.0
$ date
Wed Mar  8 12:55:29 IST 2017
$ exit

Script done on Wed Mar  8 12:55:32 2017
$
人工脚本

SCRIPT(1)                 BSD General Commands Manual                SCRIPT(1)


NAME
     script -- make typescript of terminal session

SYNOPSIS
     script [-adkpqr] [-F pipe] [-t time] [file [command ...]]

DESCRIPTION
     The script utility makes a typescript of everything printed on your terminal.  It is useful for students who need a hardcopy record of an interactive session
     as proof of an assignment, as the typescript file can be printed out later with lpr(1).

     If the argument file is given, script saves all dialogue in file.  If no file name is given, the typescript is saved in the file typescript.

请尝试
ksh-x./runScript.ksh>outPutFile.txt
Hi,@codeforester,输出相同:(跟踪部分转到stderr.So,
ksh-x./runScript.ksh&>outPutFile.txt
script
可能是您想要整个会话的选择。
ksh-x./runScript.ksh&>outPutFile.txt
导致了一个空白文件。我想把命令放在一个shell脚本中,因为稍后我会在其中添加更多命令。我想这是不可能的。)他
script
command只能在终端上输入命令?嗨,@Sharad,我可以把它放在shell脚本中吗?因为稍后,我会在shell脚本中添加许多命令。谢谢。