Shell Programming Notes (i) __ programming

Source: Internet
Author: User

Tee Cat >> Test << delimiter use file descriptors for redirection (0 1 2) redirect standard output and standard error to separate file/dev/null redirect two file descriptors, exec n>&m

Tee

To redirect output to files and screens at the same time:

Date | Tee now

Cat >> test << delimiter

Use a custom delimiter to create a document
Delimiter is a delimiter, customizable, and we're using append redirection
The above command means:

The current document, as input to cat, redirects the output (append) of cat to test

The current document refers to this section:
using file descriptors for redirection (0 1 2)

is actually redirecting standard input, standard output, and standard errors to the specified file

EXEC 1>out

After this command is executed, the output is redirected to the out file, and there is no more output on the screen
To redirect the output back to the terminal, execute:

EXEC 1>/dev/tty

The most we use is the normal input and output redirection

cmd n>file
cmd n>>file

Change the value of N to redirect the output information of the cmd command or error message to the file

CMD 0<file

The command is to redirect input to file redirection standard output and standard error to a separate file

CMD 1> file1 2> file2

The above command redirects the output of the cmd command to the FILE1, redirecting the standard error to the File2
We can also redirect standard output and standard errors to the same file, as follows:

CMD 1> file1 2>&
/dev/null

Explain this file, he is more special, if we use the following command to redirect the output of the cat command to a file, the contents of the file will become empty: cat/dev/null > File
REDIRECT two file descriptors, exec n>&m

For example, we now associate a file descriptor with a file:

EXEC 4>file

And then we'll execute the order.

EXEC 5>&4

After this command is executed, file descriptors 4 and 5 all point to file file , that is, 5 is 4 copy
Then we execute LS 1 >&5, and LS 1>&4 is the same effect
LS output will be redirected to file file

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.