Part I:
it was stated that "to redirect Error to output std, you have to write the following code"
[root@testsrv3 ~]# ls -alt FileNotThere File > logfile 2>&1 [root@testsrv3 ~]# cat logfile ls: cannot access FileNotThere: No such file or directory -rw-r--r-- 1 root root 0 2010-02-26 05:34 File
but if i changed the order as follows, only the output will be stored in the file:
[root@testsrv3 ~]# ls -alt FileNotThere File 2>&1 > logfile ls: cannot access FileNotThere: No such file or directory [root@testsrv3 ~]# cat logfile -rw-r--r-- 1 root root 0 2010-02-26 05:34 File
my question is, how we can use the logic to describe this?
maybe i have miss understand the redirection char '>' concept. as i understand, it forwards the contents of some fd to other fd. ie, 2>&1 will forward the stderror to stdout and if we add ">logfile" the contents of stdout (which include stdout and stderr) will be redirected to the file, but that is not happened
can anyone explain the fd duplication, and how we can create fd (other than 0,1 and 2) and how we can deal with them.
Part II:
i have seen an example of creating a fd:
exec 5<&1 echo "TEST" >&5 exec 5>&-
as in the page, this was intended to redirect the stdout to the fd 5 and create it, and close it. i have the following questions:
- what is exactly the meaning of second command? is it to redirect the command stdout "test" to the fd 5? and how i can see the contents of the fd 5?
- in the first command, why the < is used instead if > and what is the difference between the below two commands as in the info bash *Redirection section
Quote
----------------------------------
The redirection operator
[N]<&WORD
is used to duplicate input file descriptors. If WORD expands to one
or more digits, the file descriptor denoted by N is made to be a copy
of that file descriptor. If the digits in WORD do not specify a file
descriptor open for input, a redirection error occurs. If WORD
evaluates to `-', file descriptor N is closed. If N is not specified,
the standard input (file descriptor 0) is used.
The operator
[N]>&WORD
is used similarly to duplicate output file descriptors. If N is not
specified, the standard output (file descriptor 1) is used. If the
digits in WORD do not specify a file descriptor open for output, a
redirection error occurs. As a special case, if N is omitted, and WORD
does not expand to one or more digits, the standard output and standard
error are redirected as described previously.
i know it is a long question but i need some guides because man pages and info bash (Redirection section) make me confused.

Help


