Shell script Programming {2} per day

Source: Internet
Author: User

redirect

$echo "Test Redirect" > Temp.txt--Writes the output to the Temp.txt,temp.txt file is first emptied.

$echo "Test redirect Second" > Temp.txt-Append the output to the temp.txt.

File descriptor

0--stdin Standard Input

1--stdout Standard output

2--stderr standard Error

File descriptors and redirects

$xx 2>err.txt--Output the error message to the Err.txt file.

$ls 1>out.txt--the console information output to out.txt,1 and 2 can be specified at the same time.

$xx >output.txt 2>&1--The error message is also output to output.txt, because > is equivalent to 1>, which is the standard output. 2>&1, redirect the error to standard output.

$xx &> output.txt--&> indicates that both standard output and errors are output to the destination file.

$xx 2>/dev/null--/dev/null is a special file, the content redirected to it will be discarded.

Retain original copy of data after redirection

$echo T1>t1.txt

$echo T2>t2.txt

$chmod T1

$cat t* | Tee-a Test_tee.txt | Cat-n--Use the tee command to read the standard input and save the standard output to the specified file, after which you can continue to use the pipeline.

Note: Tee-a,a:append. Cat-n,n:number.

File redirection to Input

$cat <<eof>>log.txt

The input between the $EOF--eof is output to Log.txt.

Create a custom file descriptor

$echo Test line > Input.txt

EXEC 3<input.txt

Cat-n <&3--Read the input by a file descriptor, read only once, and read again the file descriptor needs to be reassigned.

Shell script Programming {2} per day

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.