Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-11-2008, 05:28 AM   #1
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
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.

Old 09-11-2008, 05:31 AM   #2
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
First copy stderr to stdout, then use tee to copy stdout to a file:
Code: 2>&1 |tee out.log
Old 10-12-2017, 02:38 PM   #3
Mr. Macintosh
Registered: Sep 2015
Distribution: Debian, Ubuntu
Posts: 263

Rep: Reputation: 55
Originally Posted by matthewg42 View Post
First copy stderr to stdout, then use tee to copy stdout to a file:
Code: 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?
Old 10-12-2017, 03:17 PM   #4
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,453

Rep: Reputation: 1057Reputation: 1057Reputation: 1057Reputation: 1057Reputation: 1057Reputation: 1057Reputation: 1057Reputation: 1057
Just try it, you'll find out.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: How to Redirect Output to File, AND Still Have it on Screen edwin11 Linux - Software 27 10-20-2017 03:45 AM
Shell scripting: How to redirect output from within the script itself? Arodef Linux - General 4 05-23-2006 07:30 PM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
Is there a way in Linux/Unix bash to turn off output or redirect to a file jimwelc Linux - Newbie 6 01-06-2005 03:56 AM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 05:01 AM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration