I saw this line in a script:
DEVICE=`dialog --inputbox "Festplatten-Laufzeit auslesen. Gebe Sie das
gewünschte Device an: " 0 70 "" 3>&1 1>&2 2>&3`
What is
3>&1 1>&2 2>&3
doing? I know that 1 = stdout and 2 = stderr, but what are the 3
and the &
for?
Best Answer
The numbers are file descriptors and only the first three (starting with zero) have a standardized meaning:
So each of these numbers in your command refer to a file descriptor. You can either redirect a file descriptor to a file with
>
or redirect it to another file descriptor with>&
The
3>&1
in your command line will create a new file descriptor and redirect it to1
which isSTDOUT
. Now1>&2
will redirect the file descriptor 1 toSTDERR
and2>&3
will redirect file descriptor 2 to 3 which isSTDOUT
.So basically you switched
STDOUT
andSTDERR
, these are the steps:Now if the program prints something to the file descriptor 1, it will be printed to the file descriptor 2 and vice versa.