Reputation: 5742
I am trying to make a script that spits out the status on a console as well as make a log file of that. To that end, I have been using the following line in my bash script:
exec > >(tee logfile.txt)
Having this line effectively displays stdout on a console as well as store that into a logfile.txt. Now I want to capture both stdout and stderr. I tried using
exec 2>&1 >(tee logfile.txt)
and this doesn't seem to work. Why? and how can I accomplish my task?
Upvotes: 1
Views: 1256
Reputation: 241858
Just reverse the order of redirections. It helps me to read them right to left:
exec > >(tee logifle.txt) 2>&1
Upvotes: 2