Linux Learning notes-stdin/stdout redirection

Source: Internet
Author: User
Tags stdin

Input/Output redirection

The Linux system usually reads the input from a place called the standard input and writes the result of a command to the standard output feedback to us; By default, this is also the terminal (command line) that we use. If we want to change the way we input and output, we need to use redirection. There are usually several ways to redirect commands:

Command Description
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 redirect files with file descriptor N to file.
n >> File Files with file descriptor n are redirected to file in an append manner.
N >& m Merges the output file m and N.
N <& m Merges the input file m and N.
<< tag Enter the contents of the tag between tag and end tag tags as input.

It is important to note that:

File descriptor 0 is typically standard input (STDIN)

1 is standard output (STDOUT)

2 is standard error output (STDERR)

Example 1: Output redirection

!/bin/bashecho"stdout redirection""stdout redirection  "redirected  Files" myfile "echo"stdout redirection again" " >> " indicates that the redirected content is attached to a file and does not overwrite the previous content

Example 2: Input redirection

!/bin/bashecho < myfile #将输出 the contents of the "myfile" file

Here Document

Its function is to treat all content between two EOF as a whole text, syntax:

Command << EOF    documenteof

Example:

#!/bin/bashcat << years old!! EOF
years old!!

Linux Learning notes-stdin/stdout 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.