9-shell echo Command

Source: Internet
Author: User
Tags echo command

Shell echo Command
The echo command of the Shell is similar to the echo command of PHP, and is used for the output of strings. Command format:
echo string
You can use echo to achieve more complex output format control.
1. Display normal string:
echo "It is a test"
The double quotes here are completely omitted, and the following commands are identical to the previous instance:
Echo It is a test
2. Show escape characters
echo "\" It is a test\ ""
The result will be:
"It is a test"
Similarly, double quotes can also be omitted
3. Display Variables
The read command reads a row from the standard input and assigns the value of each field in the input row to the shell variable
   #!/bin/sh
Read name
echo "$name It is a test"
The above code is saved as test.sh,name to receive the standard input variables, the result will be:
[Email protected] ~]# sh test.sh
OK #标准输入
OK It is a test #输出
4. Show line breaks
   #!/bin/sh
echo "ok!\ n"# \ n line-break
echo "It it a test"
Output Result:
Ok!

It it a test
5. Show No Line break
   #!/bin/sh
echo "ok!\c# \c does not break the line
echo "It is a test"
Output Result:
Ok! It is a test
6. Show Results directed to file
echo "It is a test">MyFile
7. Output strings As-is, without escaping or taking variables (in single quotes)
echo ' $name \ '
Output Result:
$name \ "
8. Show command execution results
Echo' Date '
Note: The use of anti-quotes ' instead of single quotes is used here.
The result will show the current date
Thu Jul 10:08:46 CST 2014




9-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.