Shell echo Command

Source: Internet
Author: User
Tags echo command

Echo is an internal command of the shell that prints the specified string on the screen. Command format:

    1. Echo Arg

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

Show escape characters
    1. echo "\"It is a test\ ""

The result will be:
"It is a test"

Double quotes can also be omitted.

Show variables
    1. Name="OK"
    2. echo "$name It is a test"

The result will be:
OK It is a test

The same double quotation marks can also be omitted.

If the variable is connected to another character, you need to use curly braces ({}):

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

The result will be:
8-1-2009

Show line breaks
    1. echo "ok! \ n"
    2. Echo "It is a test"

Output:
Ok!
It is a test

Show No Line breaks
    1. echo "ok! \c"
    2. Echo "It is a test"

Output:
Ok! It si a test

Show results redirected to file
    1. Echo "It is a test" > MyFile
Output string AS-is

If you want to output the string as-is (without escaping), use single quotation marks. For example:

    1. echo ' $name\ '
Show command Execution results
    1. Echo ' Date '

The result will show the current date

As can be seen from the above, double quotes are dispensable, single quotes are mainly used in the original output.

Shell echo Command

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.