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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can command output be redirect to file and screen?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would like to grab the output of a command and save it to a file as well as displaying it on the screen (which it does by default), is this possible? I was able to get one or the other but not both.
 
like this

ls -l | tee a_file.txt

displays on screen and saves in a_file.txt Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Here's a function I wrote to do just that.

just set a value for LOG_FILE

Write () # Display a message on screen and log to a file
# usage: Write "[Your message here]"
{
MESSAGE="$1"
eval "echo \"$MESSAGE\""|tee -a $LOG_FILE
}

# Test Run
Write "Hello There!"

Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top