Shell Learning Note Nine (redirect)

Source: Internet
Author: User

REDIRECT concept: Change the default input and output to another input/output file identifier Linux uses 0-9 to indicate the data flow associated with a particular process, and the system will open three files for that process when it starts a process: standard input (stdin), standard output (stdout ), the standard error output, identified by using the file identifier 0,1,2, will need to be identified starting with the integer 3 if you want to open additional input output for the process. By default, standard input is keyboard, standard output and error output for monitor I/O redirection 1, standard output overlay redirection (>) ls-l > Test.txt Note: If the specified file does not exist, the command            File is created first the above command is equivalent to: ls-l 1>test.txt ls-l/usr/noexist 2> ls_noexist_err.txt error redirect Output If the output of the command has both standard output and error standard output, you can specify the contents of different identifiers separately command 1> stdout.txt 2> stderr.txt 2, standard output append redirect (&            gt;>) and the use of > consistent, but this is appended, will not empty the original file 3, identity output redirection (>&) The role of standard output redirection is to redirect the output of one identity to the input of another identity.                    Example: Redirecting standard output and standard error output to a file COMMAND > Test.txt 2>&1 If you don't care about the error output        COMMAND > Test.txt 2>/dev/null #/dev/null is a special device, like a black hole 4, standard input redirection < 5, pipe (|) 6, exec exec is the shell's built-in command, 7, here Document is used to enter text in the command by line, the format is <<delimiter,Where delimiter is a separator for labeling, and all inputs are treated as input text until the next delimiter appears.            This function is mainly due to the fact that the signals completed by Ctrl+d are available in an interactive environment, but are not available in scripts.                Example: #cat here.txt line1 line2 line3 line4                #现在想要在here the third line of. txt insert a new line #!/bin/bash Ed Here.txt <<end 3                D I this is new line3. Wq END #cat here.txt line1 line2 This is new L                Ine3 line4 that is, we write all the commands we want to enter in the terminal in a single file, which is equivalent to simulating our keyboard input #对一串输入字符排序                 #!/bin/bash sort <<end SDT T Dsaj DSG FDG we GH AVF END so that you can at any time To sort the strings.   Space: 1, test comparison, the operator must have a space on both sides   2, if [], if and [] there is a space between 3, [expression] expression on both sides to have a space 4, arithmetic and assignment no space 5, while and after the expression has a space such as: while E Xpression

Shell Learning Note Nine (redirect)

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.