Saving and restoring standard file descriptors of shell scripts
How can a shell script save and restore its standard file descriptors (stdin, stdout and stderr)?
Re: Saving and restoring standard file descriptors of shell scripts
Angel Tsankov wrote:
[color=blue]
> How can a shell script save and restore its standard file descriptors
> (stdin, stdout and stderr)?[/color]
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 ...)