Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to get 1> to append to a current file

Status
Not open for further replies.

KornLearner

Programmer
Apr 19, 2012
2
US
Keyword search for "1>" turns up over 3000 results..

My shell script is using ksh. Part of it is running a program that outputs to the terminal, I would like that output to be appended to a log file that the script is already outputing to. If I change it so that the line reads
Code:
program 1>logfile
the log file is completly over written by the output of the command.

Is anyone aware of a way to have it be appended instead of overwriting?
 
D'oh, temporary lapse in memory

this works how I expect it to
Code:
program 1>>logfile
 
The "1" is unnecessary. The "1" is implied. This will do the same thing.

Code:
program >> logfile

The only problem is, if your program outputs any error messages, they will NOT be captured in the log file. This can be misleading later on when you are trying to figure out why something didn't work. This will capture both the normal output AND the error messages in the same log file.

Code:
program >> logfile 2>&1

The "2>&1" construct (no spaces), means to also send error output ("2>") to the same place standard output is going ("&1").

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top