开发者

send output to file from within shell script

I'm creating a script for users to run. I need to redirect the output to a file I'm creating from inside the scrip开发者_运维知识库t (hostname-date).

I have all the pieces except for how to copy the output of the script from inside the same script. All the examples I can find call the script and > it into the log, but this isn't an option.

-Alex


Add the following at the top of your script:

exec &> output.txt

It will make both stdin and stderr of the commands in the rest of your script go into the file output.txt.


exec in bash allows you to permanently redirect a FD (say, stdout) to a file.


A shell that calls a shell.

Have the first shell create the variable (hostname-date) and call the second shell redirecting the output to the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜