5

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: http://unix.stackexchange.com/questions/80988/how-to-stop-redirection-in-bash – sprightlyoaf Jan 31 '16 at 00: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 01:02

1 Answers1

4

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.

Michael Homer
  • 76,565