Shell Script Usage Tips 2

Source: Internet
Author: User

0--stdin Standard input

1--stdout Standard Output

2--stderr standard Error

redirect

echo "This was a good idea" > Temp.txt

Temp.txt content will be emptied first before entering "this is a good idea"

Additional

echo "This was a bad idea" >> temp.txt

Cat Temp.txt

Print exit Status: Echo $?

LS + 2>out.txt

2 input error, output to OUT.txt

CMD 2>stderr.txt 1>stdout.txt

Correct output to Stdout.txt, error output to stderr.txt;

Redirect to the same file:

CMD 2>&1 output.txt

Tee

Print stdout and redirect to a file: Tee

Command | Tee file1

Cat A * | Tee-a OUT.txt | Cat-n

-A overwrites the file,-n adds a numeric number to the file

Redirect text blocks inside the script

#! /bin/bash

Cat<<eof>log.txt

LOG FILE HEADER

This is a test log file

Function:system Staticstics

Eof

Shell Script Usage Tips 2

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.