Shell Script Learning Note 10: Shell input and output redirection

Source: Internet
Author: User

command > file redirects the output to file.

Command < file redirects the input to file.

command >> file redirects the output to file in an append manner.

n > file redirects the file descriptor n files to filename.

n >> files redirect files with file descriptor N as an append to file.

N >& m merges the output file m and N.

N <& m merges the input file m and N.

<< tag will start to tag the contents of tags between tag and end tag as input.

Note: File descriptor 0 is typically standard input (STDIN), 1 is standard output (STDOUT), and 2 is the standard error output (STDERR).

Output redirection

    • < overwrites the contents of the file
    • << does not overwrite the contents of the file, appending the output to the end of the file

Execute command and then save the output to File1 (overwrite file1 original content)

Command > File1

Executes command, then appends the output to the end of the File1 file (without overwriting the original contents of File1)

 Command >> File1

Input redirect

Get content from File1

 Command < File1

Here Document

redirect input to an interactive Shell script or program

Command << delimiter

Document

Dilimiter

 Note:

1, the end of the delimiter must be shelf write, the front cannot have any characters, the back can not have any characters, including spaces and tab indentation

2, the beginning of the delimiter before and after the space will be ignored

WC -L << EOF    Welcome to learn the    Shell scripting language    happy every day EOF

/dev/null file

If you want to execute a command but do not want the output to be displayed on the screen, you can redirect the output to/dev/null

 Command >/dev/null

The Shell file contains

The Shell can also contain external scripts. This makes it easy to encapsulate some common code as a standalone file

. FileName

Or

Source FileName

Shell Script Learning Note 10: Shell input and output redirection

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.