exec command help

All,

I am using below shell script to output the content to outputfile.txt. What I am looking for is in addition to outputfile.txt, I want the output to be on standard output too.

exec > outputfile.txt
echo "Starting "
echo "ending"

t="tee -a outputfile.txt"
echo "Starting " | $t
echo "ending" | $t

Hi,

The reason I am using exec is I dont want to output all the standard output to file without having to bother writing redirection/tee at each and every echo statement.

This command sequence is not valid in any shell.

Please post your actual script with sample input and output against expected input and output.
Please also state which shell you are using. There are techniques which would work in say "ksh" but not in every shell.

Hi Methyl,

This is working for me. I cannot find any issue with above script.

---------- Post updated at 03:54 PM ---------- Previous update was at 03:53 PM ----------

bash-2.05$ cat outputfile.txt
Starting
ending
bash-2.05$ echo $SHELL
/bin/csh
bash-2.05$

Ah it's csh with a bash prompt.

I can't comment about csh but in ksh, bash etc. we would say:

scriptname | tee -a outputfile.txt

Where the scriptname contains.

echo "Starting "
echo "ending"