The difference between single and double quotation marks
Single quote: Must be used in pairs, it can protect all characters from being translated. such as variable $, and odd number of single quotes do the same, an even number of single quotes = 1 double quotes
Double quotation marks: must appear in pairs, it can protect some meta-characters are not translated, but allow variables and command substitution, and even a number of single quotation marks the same effect
The backslash \:shell also does not explain the characters after the escape character, ' $ ' and ' \$1 '.
Single and double quotation marks can protect each other
Example 1:
$ cat test.sh
#!/bin/bash
echo "$" =$1 "$" =$2
Echo ' $ ' =$1 ' =$2
$./test.sh Hello World
Hello=hello World=world
$1=hello $2=world
Example 2:
#!/bin/bash
Echo ' $ ' =$1
Echo ' $ ' = ' $ '
Echo ' $ ' = ' $ '//a double quote
Echo ' $ ' = $
Echo ' $ ' = '$ '
Echo ' $ ' = ' $'//two single quotes
Example 3:
Backslashes in single quotes are not translated
$echo ' \ \ '
\\
Example 4:
Single quote protected double quotation mark
$echo ' mother yelled, ' time to eat! ' ‘
Mother yelled, "Time to eat!"
Example 5:
Double quotation mark Protection single quotation mark
$echo "Hi, I ' m glad to mee you"
Hi, I ' m glad to meet
The difference between single and double quotes in bash