Linux Shell Io redirection

Source: Internet
Author: User

I. Io Devices

Io is the source and destination of the index data, which are called standard input, standard output, and standard error output.

Programs do not have to worry about device issues, such as files, terminals, and tape drives.

 

By default, the system reads standard input, writes standard output, and passes errors to standard output. By default, standard input, output, and errors are all terminals.

We can see from the following:

$ Cat

Input testing # user input

Input testing # screen output

Second testing # user input

Second testing # screen output

 

When logging on to Linux, the terminal is set as a standard input, output, or error device by default.

 

 

2. redirection and Pipelines

Redirection:

Change the default standard input, output, and error terminal device.

Use "<" to change the default input: Program <file. You can change the standard input of program to file.

 

Use ">" to change the default output: CAT file. You can change the standard output of the terminal to file.

 

">" Is special. It is an append output.

Example: CAT> File

The terminal input is appended to the end of the file. If the file does not exist, the file is automatically created.

 

MPs queue:

You can connect more than two programs in progress.

Example: TR-d '/R' <file.txt | sort> file2.txt

Delete the line breaks in file.txt and then sort them. And save the result as a file2.txt input file.

 

 

3. Access shell script Parameters

Shell parameters refer to shell script command line parameters. In Shell functions, they are also parameters of Shell functions. Each parameter is named by an integer.

When there are more than 9 of them, use {} to enclose them. Example: $ {10}

 

For example, write a simple shell and return the terminal with the current connection similar to the condition name.

$ Cat who. Sh

#/Bin/sh

Who-A | grep $1

 

$ Chmod x + who. Sh

./Who. Sh tty

Returns the connection information with the terminal Name TTY.

 

 

Iv. Script tracking and execution

When writing complex scripts, tracking the script execution process will help to detect script errors and improve writing efficiency.

Set-X indicates that tracking is enabled.

Set + X indicates that the trail is stopped.

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.