|
|
|
|
|
|
| Author |
Message |
Andrew Schulman *nix forums Guru Wannabe
Joined: 20 Feb 2005
Posts: 168
|
Posted: Sat Feb 12, 2005 3:49 pm Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
| Quote: | Is this a redirection of ALL (?) output of ALL (?) statements to the file
myfile.dat?
|
Yes, but just stdout. Not stderr.
| Quote: | Wouldn't it be better to use tee instead?
|
It depends what you want to do. 'exec >file' redirects stdout away from the
console and into file, for all future commands run in this shell. 'cmd |
tee file' sends a copy of stdout from that one command into file, while
also sending it to the console. Not better or worse, just different.
--
To reply by email, replace "deadspam.com" by "alumni.utexas.net" |
|
| Back to top |
|
 |
Bill Marcum *nix forums Guru
Joined: 28 Mar 2005
Posts: 1264
|
Posted: Wed Feb 09, 2005 3:01 pm Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
On Wed, 9 Feb 2005 01:05:40 +0100, Peter Hanke
<peter_ha@andres.net> wrote:
| Quote: | Is this a redirection of ALL (?) output of ALL (?) statements to the
file myfile.dat?
Wouldn't it be better to use tee instead?
That depends on what you want to do. |
Tee copies its input to a file and to standard output.
"exec >myfile.dat" sends output only to the file, and the output is
redirected until the shell ends or until another exec command is given. |
|
| Back to top |
|
 |
Villy Kruse *nix forums Guru Wannabe
Joined: 04 Mar 2005
Posts: 117
|
Posted: Wed Feb 09, 2005 7:48 am Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
On 8 Feb 2005 23:28:19 -0600,
Larry Starr <starrl@dragonone.localdomain> wrote:
| Quote: | In article <cubk4k$i1h$01$1@news.t-online.com>, Peter Hanke wrote:
Is this a redirection of ALL (?) output of ALL (?) statements to the file myfile.dat?
Wouldn't it be better to use tee instead?
Peter
With no command to exec, the exec command will respawn the current
shell, with the IO redirection supplied. The example, in your subject
line, will redirect standard out to myfile.dat, stdandard error etc.
will NOT be affected.
|
I would rather say that the IO is redirected as indicated and no rewpawn
takes place. If a respawn would indeed take place I would expect most
of the current execution state would be lost, including the current
position in the shell script and all non-exported variables.
Villy |
|
| Back to top |
|
 |
Larry Starr *nix forums beginner
Joined: 09 Feb 2005
Posts: 5
|
Posted: Wed Feb 09, 2005 4:28 am Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
In article <cubk4k$i1h$01$1@news.t-online.com>, Peter Hanke wrote:
| Quote: | Is this a redirection of ALL (?) output of ALL (?) statements to the file myfile.dat?
Wouldn't it be better to use tee instead?
Peter
|
With no command to exec, the exec command will respawn the current
shell, with the IO redirection supplied. The example, in your subject
line, will redirect standard out to myfile.dat, stdandard error etc.
will NOT be affected.
It is useful for capturing output, that would normally print to the
screen without having to redirect each command in the script.
For example:
exec >myfile.dat
some command
another command
command
command
command
would place the standard out of all executed commands in myfile.dat
and is much less tedious than:
some command | tee -a myfile.dat
another command | tee -a myfile.dat
command | tee -a myfile.dat
command | tee -a myfile.dat
command | tee -a myfile.dat
I tend to use it mostly in scripts that will be running in cron.
Using descriptor duplication, and redirection, I can direct segments
of the output to various files, without having to remember, when
modifying areas of the script, where the output should currently be
going.
Hope this helps.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- |
|
| Back to top |
|
 |
Barry Margolin *nix forums Guru
Joined: 24 Feb 2005
Posts: 323
|
Posted: Wed Feb 09, 2005 3:52 am Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
In article <cubk4k$i1h$01$1@news.t-online.com>,
peter_ha@andres.net (Peter Hanke) wrote:
| Quote: | Is this a redirection of ALL (?) output of ALL (?) statements to the file
myfile.dat?
|
Yes.
| Quote: | Wouldn't it be better to use tee instead?
|
Tee writes to (at least) two places: the file and the original stdout.
Also, to use tee you have to use a pipe, and this causes the commands to
be run in a subshell. The syntax you asked about is often used when you
want to redirect the output of lots of commands, but need to stay in the
original shell process because you're setting variables that must
persist after you redirect output back to the original stdout.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me *** |
|
| Back to top |
|
 |
Si Jingnan *nix forums beginner
Joined: 09 Feb 2005
Posts: 1
|
Posted: Wed Feb 09, 2005 1:12 am Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
Peter Hanke wrote:
| Quote: | Is this a redirection of ALL (?) output of ALL (?) statements to the file myfile.dat?
Wouldn't it be better to use tee instead?
Peter
Seems to empty/delete the file myfile.dat |
I try it under a bash,if the file exist, it will be deleted, if it
doesn't exist,nothing will happen.
Si Jingnan |
|
| Back to top |
|
 |
Erkan Yanar *nix forums beginner
Joined: 27 May 2005
Posts: 6
|
Posted: Tue Feb 08, 2005 11:21 pm Post subject:
Re: What does the statement "exec >myfile.dat" mean?
|
|
|
Am Wed, 9 Feb 2005 01:05:40 +0100,schrieb Peter Hanke :
| Quote: | Is this a redirection of ALL (?) output of ALL (?) statements to the file myfile.dat?
|
If your first ALL means only STDOUT -> yes.
| Quote: |
Wouldn't it be better to use tee instead?
|
Not if you dont want no output on your terminal ;-)
tschazu
erkan
--
über den grenzen muß die freiheit wohl wolkenlos sein |
|
| Back to top |
|
 |
Peter Hanke *nix forums beginner
Joined: 08 Feb 2005
Posts: 2
|
Posted: Tue Feb 08, 2005 11:05 pm Post subject:
What does the statement "exec >myfile.dat" mean?
|
|
|
Is this a redirection of ALL (?) output of ALL (?) statements to the file myfile.dat?
Wouldn't it be better to use tee instead?
Peter |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Fri Jan 09, 2009 1:04 am | All times are GMT
|
|
Problem Mortgage | Mobile Phone | Personal Loans | Loans | Debt Consolidation
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|