Shell script echo command using tips _linux shell

Source: Internet
Author: User
Tags echo command

ECHO is an internal instruction of the shell to print out the specified string on the screen. Command format:

Copy Code code as follows:

Echo Arg

You can use echo to achieve more complex output format control.

Show escape characters

Copy Code code as follows:

echo "\" It is a test\ ""

The result will be:
"It is a test"

Double quotes can also be omitted.

Show variables

Copy Code code as follows:

Name= "OK"
echo "$name It is a test"

The result will be:
OK It is a test

The same double quotation marks can also be omitted.

You need to use curly braces ({}) if the variable is connected to another character:

Copy Code code as follows:

Mouth=8
echo "${mouth}-1-2009"

The result will be:
8-1-2009

Show Line Wrapping

Copy Code code as follows:

echo "ok!\n"
echo "It is a test"

Output:
Ok!
It is a test

Show No Line wrapping

Copy Code code as follows:

echo "Ok!\c"
echo "It is a test"

Output:
Ok! It si a test

Show results directed to file

Copy Code code as follows:

echo "It is a test" > myfile

Output string AS-is

Use single quotes if you want to output strings as they are (without escaping). For example:

Copy Code code as follows:

echo ' $name \ '

Show Command Execution results
Copy Code code as follows:

Echo ' Date '

The result displays the current date

As you can see from the above, double quotes are dispensable, and single quotes are mainly used in the original output.

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.