Shell's text processing-echo

Source: Internet
Author: User
Tags echo command
one echo command output text 1.1 displaying normal strings

echo [Options] string

option means that the command option, only-n, does not output a newline character at the end of the line.

If the text you want to output is made up of multiple lists, enclose it in double quotation marks.

Echo-n "What's your first name?" 1.2 Show escape characters

To use the echo command to support escape characters, use the-e option.

\b Backspace

Echo-e "This is a\b string" (output this is string)

\c suppress continuation of output text

Echo-e "Hello \c world." (Output Hello)

\ r return character

\ n line break

1.3 Display variables

The Echo statement prints the value of a variable in the program, and you can use {} to define the variable name.

Echo-n "Please input a name:"

Read name

#输出变量的值

echo "Hello, $name"

v1= "Sing"

V2= "Danc"

#错误的输出变量值的方法

echo "We are $v 1ing and we are $v 2ing."

(Correct echo "We are ${v1}ing, we are ${v2}ing.") 1.4 Show Command execution results

Echo can display the results of the execution of the shell command, using the anti-quote "' to bring the command.

echo ' command ' 1.5 echo command execution result redirection

Redirection is the standard output of a shell command that is redefined to a file. By default, the standard output device for the echo command is a monitor, and sometimes the information displayed by the echo command is saved to a disk file. Redirect is now necessary.

The redirected operator is > or >>, and in the case of the target file, the former overwrites the original contents of the destination file, which appends the data to the end of the original file.

#将要输出的信息写入文件, it will overwrite

echo "Hello,world." > Hello.txt

#将输出的信息追加到文件的结尾, will not overwrite

echo "Hello,chunxiao." >> hello.txt


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.