我是shell脚本的初学者,这是我的示例脚本:
Public ActionResult Index(string show)
{
if (User.Identity.IsAuthenticated && String.IsNullOrEmpty(show))
{
Return RedirectToAction("Dashboard","Manage");
}
else
{
Return View();
}
}
我通过此命令运行它:#!/bin/ksh
echo "start script"
ls
echo "end script"
并获得文件内的输出:
./runScript.ksh > outPutFile.txt
我只想问一下是否有可能在文件上输出此内容?如果在终端上执行命令会显示什么?:
start script
file1.txt
file2.txt
file3.txt
end script
提前非常感谢你。我真的很感激任何帮助。
答案 0 :(得分:0)
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
$
<强> man script
强>
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.