I don't understand this line:
exec {logOutFd}>&1 {logErrFd}>&2
There are no variable dereferences, and it seems to be just a no-op, like running exec
with no parameters. What's going on?
exec
with no parameters is used to start redirections that last for the rest of the script.
From the Bash manual section on redirection:
Each redirection that may be preceded by a file descriptor number may instead be preceded by a word of the form {varname}. In this case, for each redirection operator except
>&-
and<&-
, the shell will allocate a file descriptor greater than 10 and assign it to {varname}.
So this is duplicating stdout and stderr to new file descriptors, and setting the variables $logOutFd
and $logErrFd
to these descriptors, respectively.
This allows later code that executes while stdout or stderr are redirected to write to the original stdout or stderr, with
echo stdout message >&$logOutFd
Reviewing other preceding script: https://github.com/search?q=repo%3ANixOS%2Fnixpkgs%20%20logOutFd&type=code
And reading:
They are using complex i/o redirections to return the stream pointer from some files previously open (8 and 9 position) to the classic stdout and stderr
exec 8>&1 9>&2