Post by Angel TsankovHow can a shell script save and restore its standard file descriptors
(stdin, stdout and stderr)?
one common trick is
# move FD 1 to FD 20
exec 20>&1 1>&/some/other/file
...
# move FD 1 back to original
exec 1>&20
this assumes that shell supports multidigit FD number (some older shells do
not) and FD 20 is not used (e.g. it may be inherited and contain SSH agent
connection ...)