I have a pretty good idea how file descriptors work in Bash to accomplish I/O redirection in a practical level, but there is a case I found online (https://linuxcommand.org/lc3_adv_dialog.php, under "Method 2: Using Command Substitution and Redirection") that I do not fully understand why it is being used.
There is an execution that requires to redirect the stderr to stdout in order to capture the errors in a command substitution and that makes perfect sense to me, but there is an extra redirection that is done that I feel requires knowledge of how file descriptors work in a lower level. Pseudocode:
exec 3>&1
...
var=$(cmd -options ... 2>&1 1>&3)
...
exec 3>&-
What is the point of making a backup of stdout and redirect stdout to the location it was already pointing to? stdout was never altered besides now receiving the contents of stderr.
My best guess is that fd 3 contains the original state of stdout and redirecting fd 1 to fd 3 returns it to its original state before having fd 2 redirected to it? I would love some insight or reading materials.