1)
Redirection error:
>>>
Cannot redirect
Stderr
, Use
2>
2>
Error redirection
2)
Redirection at the same time
Stdout
,
Stderr
:
Xxx 1> a.txt 2> a.txt
Or
Xxx
&> A.txt
Or
Xxx
> & A.txt
3)
Redirect to file descriptor:
Use
&
:
> & N
Eg:> & 2
Redirect
Stderr
4)
Permanent redirection in the script:
Exec
1> t.txt
Exec
1> t.txt
#
Append
>
Exec
0 <t.txt
Do not have spaces on either side of the redirection symbol
The script can be opened at the same time.
9
File descriptors, which can be customized
3
~
8
Exec
3> t.txt
Echo
"ABC"> & 3 #
Output
T.txt
5)
Storage and recovery of descriptors:
Exec 4> & 1
#
Storage
1
To
4
Exec 1> a.txt
#
Set
1
Echo "BBBB"
#
Output
A.txt
Exec 1> & 4
#
Restore
1
Echo "aaaa"> & 1
#
Output
Stdout
Similarly:
Exec 4 <& 0
#
Storage
0
To
4
Exec 0 <A. In
#
Redirect Input
Exec 0 <& 4
#
Restore
Stdin
6)
Readable and writable file descriptor:
Exec 3 <> a.txt
#3
Can be used for both input and output
Exec 3> &-
#
Close
3
Eg:
Exec 4> & 1
Echo "BBBB"> & 4
#
Output
Stdout
Exec 4> &-
Echo "aaaa"> & 4
#
Will report an error
7)
Redirection of the output of the entire function
You can add redirection directly after the function call.
8)
Appendix:
Lsof, view all FD in the Linux System
Lsof-p pid, view all FD of a PID