how to duplicate an output in shell script

how to duplicate an output from a shell command?

for example:
`date` will give the current date to the console.
I want this to be displayed in console and also parallely store it in file or variable.

user1@solaris4:~> date
Tue Feb 28 17:48:31 EST 2012

user1@solaris4:~> date > file

Instead of two commands i want one command / syntax that does it...
I guess it will be possible using pipe.. but i wonder how...

date | tee file

See "man tee" and also take note of the "-a" option.

1 Like

Hi,

Try this one,

date | tee -a file

tee cmd will redirect the output to file and as well as STDOUT.

Cheers,
Ranga:)

1 Like

thanks.. this what i was expecting..