Shell basics 5: Input and Output (echo, read, Cat, pipeline, Tee, redirection, etc)

Source: Internet
Author: User
Shell basics 5: Input and Output (echo, read, Cat, pipeline, Tee, redirection, etc)
All the environments below are tested in RedHat Linux9
In Linux, to make the Escape Character take effect, you need to add the parameter-e

Start with the echo variable.
For example, the Escape Character and variable output by E c h o command.

 

# Echo-e "/007 your home is $ home, you are connected on 'tty '"
Your home is/root, you are connected on/dev/pts/1
# Echo-e "/AYour home is $ home, you are connected on 'tty '"
Your home is/root, you are connected on/dev/pts/1
#

 

In this example
/007 or/A You can make the terminal RING
The $ h o m e directory is displayed,
In addition, the system can execute the t y command (note that this command is caused by the symbol in the upper-left corner of the keyboard, which is not a single quotation mark ).

Append a line break after the output of the E c h o command. You can use the/n option:

 

$ Cat echod
#! /Bin/sh
Echo-e "This echo's 3 new lines/n"
Echo "OK"

Edit a new echod, as shown above, and then run the output as follows:

 

$./Echod
This echo's 3 new lines

OK
$

Use the Escape Character in the e c h o statement. Remember to add the backslash /:

 

$ Echo-e "here is a tab/There are two tabs/T/Tok"
Here is a tab here are two tabs OK
$

Output a string to a file and use the redirection symbol>.
In the following example, a string is redirected to a file named m y f I L E:

 

$ Echo "the log files have all been done"> myfile

Alternatively, you can append the object to the end, which means that the original content is not overwritten:

 

$ Echo "$ LOGNAME carried them out at 'date'"> myfile

Now let's take a look at the content in the m y f I l e file:

 

The log files have all been done
Sam carried them out at six November 13 12:54:32 CST 2004

The quotation mark is a special character, so you must use a backslash/to make s h e l ignore its special meaning.
If you want to use the E c h o command to output a string like this: "/d e v/r m T 0", you only need to add a backslash/before the quotation marks:

 

$ Echo "/"/dev/rmt0 "/"
"/Dev/rmt0"
$

 

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.