0

Korn shell 93u+

2>&1 | tee -a ${LOGFILE} 

puts the output to a file. I want to add that command to each function I run. For example:

_cleanup_test  2>&1 | tee -a ${LOGFILE}

That works fine.

But I want to replace 2>&1 | tee -a ${LOGFILE} with a variable, so I made

logit='2>&1 | tee -a ${LOGFILE}'

That way I can have

_cleanup_test  $logit

But when I run the .ksh it reads it as

+ _cleanup_test '2>&1' '|' tee -a '${LOGFILE}'

I even tried to escape characters and a bunch of other things. How do I have it read that variable without the single quotes?

hrobertv
  • 158
  • 1
  • 8
  • You can't generally store code (especially redirections, etc.) in a variable and expect it to work without considerable extra effort. Consider the alternate `( cmd1; cmd2; cmd3; ...) 2>&1 | tee -a "${LOGFILE}"`. – twalberg Feb 25 '15 at 19:07
  • @twalberg You mean do it at the command level say inside the function rather than trying to do it at the function level? That might be best. – hrobertv Feb 25 '15 at 19:50

0 Answers0