LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 05-13-2006, 06:32 AM   #1
s_siouris
LQ Newbie
 
Registered: Nov 2004
Distribution: Scientific Linux 6.4
Posts: 22

Rep: Reputation: 0
redirecting output in bash scripts


Hi all,
I have a bash script and I know how to redirect output to either the screen or file. What I am looking for though is to have the output on both screen and file. I have seen the the "tee" command might be what I want, but I haven't managed to get it working.

Any ideas on how to do this?
 
Old 05-13-2006, 07:14 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
An example for tee:
Code:
pu@slackw:~$ echo "test output" | tee outputfile
test output
pu@slackw:~$ cat outputfile
test output
pu@slackw:~$
So basically just run your script with
Code:
 ./myscript | tee outputfile
 
Old 05-13-2006, 07:56 AM   #3
s_siouris
LQ Newbie
 
Registered: Nov 2004
Distribution: Scientific Linux 6.4
Posts: 22

Original Poster
Rep: Reputation: 0
great! this is what I want, thanks.

is there any way of including this in the script so that I only type "./myscript" ? I was thinking of some combination with "set" and "tee" (inside the sript)

cheers for your help
 
Old 05-13-2006, 08:27 AM   #4
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
I'd suggest a wrapper script, i.e. myscript is "./mysubscript | tee outputfile". This way you can run the script either with or without tee.
 
  


Reply



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
Redirecting output of background processes after they've been started (BASH) DaneM Programming 18 08-08-2011 09:03 PM
redirecting the output of pwd into konqueror as a url. using bash fiery_ice Linux - Newbie 5 04-05-2006 03:13 PM
Redirecting output into a filename pbickerd Linux - Software 10 02-24-2006 02:41 PM
Redirecting mplayer output driptray Linux - Software 1 10-12-2004 07:42 AM
redirecting xmms output durden2.0 Linux - Software 0 03-06-2004 07:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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