LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash Scripting: Redirect output of entire script to file & screen (https://www.linuxquestions.org/questions/programming-9/bash-scripting-redirect-output-of-entire-script-to-file-and-screen-669160/)

Kristijan 09-11-2008 05:28 AM

Bash Scripting: Redirect output of entire script to file & screen
 
Hi All,

Trying to get my head around this one.

How would I redirect stdout and stderr of an entire bash script to a file, but also leaving the output to the screen?

I've tried various combination of exec and tee, and I can't get anything to work =/

Any help is much appreciated.

-Kristijan

matthewg42 09-11-2008 05:31 AM

First copy stderr to stdout, then use tee to copy stdout to a file:
Code:

script.sh 2>&1 |tee out.log

Mr. Macintosh 10-12-2017 02:38 PM

Quote:

Originally Posted by matthewg42 (Post 3276922)
First copy stderr to stdout, then use tee to copy stdout to a file:
Code:

script.sh 2>&1 |tee out.log

Does this work when you're invoking it directly at the CLI or can it be used in a script?

NevemTeve 10-12-2017 03:17 PM

Just try it, you'll find out.


All times are GMT -5. The time now is 11:24 AM.