recently came across several chained redirections to file descriptors as shown is the snippet below:
name=$(dialog --inputbox "Please enter your phone number." 10 30 3>&1 1>&2 2>&3 3>&1) || exit
... while I understand this script is
- Creating a new file-descriptor
3
which is is then redirecting toSTDOUT
, - Redirecting
STDOUT
toSTDERR
STDERR
to the file-descriptor3
- Finally, redirecting file-descriptor
3
again toSTDOUT
My question is why is this being done? It looks kind of circular to me, so it would be great if someone could explain the logic or possible purpose/use-case for wanting to chain the redirections this way.
TIA!
3>&1
doesn’t serve any purpose. – Stephen Kitt Sep 08 '20 at 15:18