Background:
A lot of people have been converted from C + +, after reading the study document, stepping into a lot of pits
1 assigning values to variables don't have spaces
# correct a = 123 # error
2 if statement [] to leave a space, the variable is best to add ""
if " $a "-eq" # pair if [$a-eq] # wrong
3 in many cases want to output "! "This is a time to use single quotes
Echo ' ok! ' #对的echo "error!" # of the wrong
4 position parameter more than 10 to use the curly braces less than 10 can not
Echo ${10} # is correct, indicating that the 10th variable is printed echo $ # is also correct, but represents the first variable followed by a 0
5 Remember that uninitialized variables are null, not 0
6 double quotes in an if statement
if " $a " ] # Right if [-N $a] # Error
7 Child shell operations do not affect the parent shell
Child Shell:
# !/bin/bash string_test="TEST"export string_test
Parent Shell:
Echo $STRING _test
8 DOS-style \ r \ n is not legal in bash
Dos2unix need to convert
9 spaces appear in parameter passing
The above content appears in
The shell must read at first, it is highly recommended for beginners to read