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
3which is is then redirecting toSTDOUT, - Redirecting
STDOUTtoSTDERR STDERRto the file-descriptor3- Finally, redirecting file-descriptor
3again 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>&1doesn’t serve any purpose. – Stephen Kitt Sep 08 '20 at 15:18