Linux standard input and output

Source: Internet
Author: User
Tags stdin

After Linux startup, 3 file descriptors will be opened by default: standard input 0, correct output 1, error output: Error outputs 2

After you open the file. The new file binding descriptor can be incremented in turn. A shell command executes, inheriting the file descriptor of the parent process. Therefore, all running shell commands will have a default of 3 file descriptors.

Original address:

Linux shell data Redirection (input redirection and output redirection) detailed analysis-Cheng-Blog Park
Http://www.cnblogs.com/chengmo/archive/2010/10/20/1855805.html

A command was executed:

There is one input: the input can be from the keyboard, or the file can be

Command execution completed: successful, will output to the screen: standard output default is the screen

Command execution error: The error is also output to the screen: standard error is the default also refers to the screen

The file input and output is done by tracing the integer handle of all open files for a given process. These numeric values are file descriptors. The most known file meter descriptors are stdin, stdout , and stderr, and the number of file descriptors is 0,1 and 2, respectively. These numbers and the respective equipment are reserved. Before a command executes, all input and output will be prepared by default (Stdin,stdout,stderr), and if an error occurs at this time, the command will be terminated and will not be executed. Command parsing process, you can refer to: Linux Shell wildcard characters, metacharacters, escape character usage examples introduced

These default output, the input is the Linux system, we in the process of use, sometimes do not want to execute the results output to the screen. I want to output to a file or other device. At this point we need to redirect the output.

The common input and output operators under the Linux shell are:

1. Standard input (stdin): code 0, using < or <</dev/stdin,/proc/self/fd/0 0 for:/dev/stdin
2. Standard output (STDOUT): Code 1, using > or >>/dev/stdout,/PROC/SELF/FD/1 1 for:/dev/stdout
3. Standard error Output (STDERR): Code 2, using 2> or 2>>;/dev/stderr,/PROC/SELF/FD/2 2 for:/dev/stderr

Record a section of code.

1#!/bin/SH2 # Check the script's run parameters and exit the script if the parameter is not equal to two3 if[! $#-eq2]; Then4 Echo "Usage:need parameters! Run: $ ten"5 Exit6 fi7 #执行代码8 Echo "Para1: $"#所执行的脚本名称9 Echo "Para2: $"#所执行的脚本第一个参数Ten Echo "PARA3: $"#所执行的脚本第二个参数 One Echo "PARA4: $"#所执行的脚本第三个参数 A Echo "Para10: ${10}"#所执行的脚本第十个参数 - Echo "Para11: ${11}"#所执行的脚本第十一个参数 - Echo "Para5: $#"#所执行的脚本参数个数 the Echo "Para6: $?"#上一个代码或者shell程序在shell中退出的情况, returns 0 if normal exits, or non-0 values - Echo "Para7: [email protected]"#传递给脚本参数列表, separate each parameter with a space, forming a string - Echo "Para8: $*"#脚本参数列表, as a parameter group, quoted when used - Echo "Para9: $$"#所执行脚本的当前进程ID + Echo "Para1: $-"#显示Shell使用的当前选项, the same function as the SET command.  - Echo "Para2: $!"#后台运行的最后个进程ID

Linux standard input and output

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.