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