LinuxQuestions.org
Review your favorite Linux distribution.
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 06-24-2003, 11:12 PM   #1
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Basic BASH scripting question


I have a script, and I'd like to have it echo the standard output to a file; similar to using tee. However, I don't want to force the user to use tee or any file redirection. I want the script to do all of it by itself. Obviously, the simplest answer would be to copy every echo statement. Then change one of each pair so it's redirected to the file.

Another option would be to have a script wrapper. That is, have the wrapper script call the intended script, but add the necessary tee command.

Am I right in thinking there's a better/more elegant way of doing this?
 
Old 06-25-2003, 01:29 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
The only other thing I can think of is to echo everything to the file then "cat" or "less" the file at the end. This is probably no good if the script is slow or hangs at all.
 
Old 06-25-2003, 03:40 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You could write you own print or write method that will do the work for you:

Code:
#!/bin/sh

write()
{
   echo $@ | tee -a outfile
}

write hello dude
write another test write
 
Old 06-26-2003, 05:45 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Original Poster
Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Yeah, other people might be using this script, and it might also take a while to run. So, delaying the output might encourage widespread use of Ctrl-C and complaints that my script "hangs". So it would be a mixed bacg waiting until the end of the script and cat'ing the log file as visual output.

I like crabboy's take. That's basically what I was looking for, but just didn't make that mental leap.

Thanks guys, I appreciate the input.
 
  


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
bash scripting question Red Squirrel Linux - General 1 07-11-2005 09:57 PM
Bash scripting question. welby Linux - Software 1 01-14-2004 10:05 AM
Bash Scripting Question Rezon Programming 2 10-30-2003 10:16 AM
very basic scripting question spatter9999 Programming 3 09-18-2003 01:36 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM

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

All times are GMT -5. The time now is 08:56 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