Shell learns 37 days----references

Source: Internet
Author: User

Reference

Case , If I want to output an asterisk (*), How do i use echo ?

echo *

This is certainly not possible , need to transfer the * , that is : Echo \*

This leads to the concept of references . referenced by , is used to prevent Shell to interpret something you want to mean differently. . If you want something that might be Shell things that are treated as individual parameters remain as a single parameter , then you have to refer to it .

Three ways to refer to :

Anti-Slash escape

The character's forward backslash (\) is used to tell The shell that the character is literally meaning .

Single quotation marks

Single quotation marks (' ... ') force the shell to nonalphanumeric all the words between a pair of quotes as their literal meaning . The shell script removes both quotes , leaving only the complete text enclosed :

Command : Echo ' Here is some character *? ' $ \ '

Output :here are some character * ?  '  $ \

You cannot enclose a single quotation mark in a single quoted string . even if the backslash , there's no special meaning in single quotes. ( in some systems , commands like echo ' A\TB ' look like the Shell's special handling of backslashes , not actually , this is Echo The command itself has a special way of handling )

If you want to mix single and double quotes , You can use a backslash escape and a connection with a different reference string to do this :

Command : Echo ' He said ' how ' \ ' s tricks? '

Output : He said "How ' s tricks?"

Command "echo" she replied, \ "Movin ' along\" "

Output : She replied, "Movin ' Along"

Regardless of how it is handled , This combination is always difficult to read .

Double quotes

Double quotation marks ("...") are like single quotes , and the enclosed text is treated as a single string . just , double quotes will handle the exact characters and variables enclosed in the text , arithmetic , command Substitution :

X=hahaha

echo "$x"

Output : Hahaha

In double quotes character $, ", '

When single quotes are enclosed in double quotes, there is no special meaning , and they do not have to be accepted or transferred .

Command : echo "Hahah "

Output : Hahah '

In general , the time to use single quotes is where you want to be completely out of the process . otherwise , when you want to treat multiple words as a single string , but also need Shell doing something for you. , use double quotation marks at this time , For example, a variable value is linked to another variable value :

Oldvar= "$oldvar $newvar"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Shell learns 37 days----references

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.