You should quote the TEE assignment:
Code:
TEE="2>&1 | tee -a afile"
When you do this:
Code:
$ echo 'J. R. Bob Dobbs' $TEE
...the shell will expand the $TEE variable
after constructing the pipeline (which in this case is just a single command), and so the output is:
Code:
J. R. Bob Dobbs 2>&1 | tee -a afile
What you need to do is expand the variable first, then
evaluate the command:
Code:
eval "echo 'J. R. Bob Dobbs' $TEE"
Note that I changed your double quotes to single ones so that I could wrap the command in double quotes, which permit expansion of the $TEE, while still quoting what should be echoed. You could omit the outer, double quotes, but then you would have problems if you wished to echo something which contained multiple spaces.