Shell (3) redirection .doc

Source: Internet
Author: User



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

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.