Standard input, standard output, standard error

Source: Internet
Author: User


(1), standard input is code 0
(2), standard output is code 1
(3), standard error is code 2


REDIRECT Standard output
> writes the command output to a file or device.

< read command input from a file instead of from the keyboard or handle

>> add command output to the end of a file without deleting information already in the file

Cat passwd | Awk-f: ' {print $} ' | Sort >sort.out


REDIRECT Standard input
Cat >> Alvin.log <<eof
> My name is Alvin
> My name is Gongda
> Good bye,..
> EOF
[Email protected] ~]# ftp-i-N 127.0.0.1<<eof
> User FTP FTP
> dir
> EOF
Drwxr-xr-x 2 0 0 4096 Oct 23:54 Pub

REDIRECT Standard error
[[email protected] ~]# grep "Gongda" 111.txt
Grep:111.txt: No file or directory

Normally, an error is generated. This method standard 2 error redirection
# grep "Gongda" 111.txt 2>/dev/null


Standard output combined with standard error
# grep "root"/etc/passwd > 1.log 2>&1
2 >& 1 means that the error output is redirected to the handle 1 standard output; Combined, the standard output and error output generated during grep command execution are redirected to 1.log.

Standard input, standard output, standard error

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.