I found a great solution at Redirect all subsequent commands' stderr using exec.

I used the example:

exec > >(tee $somelog) 2>&1

...and managed to get everything to tee great. Now, how to I turn it off again?

  • 2
    Appears to have been answered here: unix.stackexchange.com/questions/80988/… – sprightlyoaf Jan 31 '16 at 0:50
  • 1
    Thank you for the link. My problem is that I just used the example, and it worked. Can't say I understand it. Hence, I do not know what was set to what before I redirected it. So I don't know what to change back. Or to what to set it. Basically, if I ran: "exec > >(tee $rrmasterlog) 2>&1" to set it, what do I run to turn it off? – Robert Roberts Jan 31 '16 at 1:02
  • Please read this answer. – user79743 Jan 31 '16 at 1:58

The best solution if you plan it in advance is probably to save the descriptors first, or to do your redirections in a subsidiary scope, as in the question linked in the comments.

If you didn't do that, though, then you can restore writing directly to the terminal with:

exec > $(tty)

provided that you haven't redirected standard input as well.

If you have redirected standard input, you can use:

exec > /dev/tty

, which is also fractionally faster.

Those reset standard output to the terminal. To reset standard error specifically, use:

exec 2> ...

for whichever option you chose from above.

If you're just stuck and want to get out of it, note that simply exiting and restarting the shell will get you back to normal as well.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.