A shell redirection note

Source: Internet
Author: User
File descriptorBefore a process reads a file, it needs to open the file. When the process opens the file, Linux associates the file with a number (called a file descriptor ), the file descriptor is an index of the opened file in the input table. Each process has its own set of opened files and their respective file descriptors. Once a file is opened, the process can read and write the file through the file descriptor. When a process does not need a file, it must close the file and release the file descriptor.
When a Linux process starts, three files are opened: standard input (file descriptor 0), standard output (file descriptor 1), and standard error (file descriptor 2 ). The child process inherits the file descriptor of the parent process. You can run the LS/proc/self/FD command to view the currently opened file descriptor.
Exec n> OUTFILE indicates opening an input file OUTFILE and associating it with the file descriptor N; Exec m <infile indicates opening an input file infile, and associate it with the file descriptor m;

<&> &<&> & Indicates that the file descriptor N is opened or redirected using exec n <& M, and is used as a copy of input file M.
Use exec n> & M to open or redirect the file descriptor N and use it as a copy of the output file M.
One instance:
Exec 4 <& 0 # Use 4 to save the copy of the standard input exec <$1 # redirect the standard input to file 1 exec 7> & 1 # use 7 to save the standard output exec> $2 # redirect standard output to file 2 cat-| tr a-Z A-Z # convert standard input to large and small output to standard output
Exec 1> & 7 7> &-# use 7 to restore standard output, disable 7 exec 0 <& 4 4 <&-# Use 4 to restore standard input, and disable 4

A shell redirection note

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.