1. When defining a variable, no spaces can be left on either side of the = number.
eg:
Gender=femal ———— Right
Gender =femal ——— –wrong
gender= femal ——— –wrong
2. Conditional test statement [Both sides of the symbol must be left blank.
eg:
if [$gender = Femal]; Then ——-right.
echo "You are Femal";
Fi
if[$gender ...-----------------------wrong
If [$gender ...----------------------wrong.
3. The content of the condition test, if it is a string comparison, the comparison symbol on both sides should be left blank!
eg:
if [$gender = Femal]; Then ——-right.
if [$gender = Femal]; Then--–wrong.
If [$gender =femal]; Then ——— wrong.
4. If the IF and then are written on the same line, then, note that the front of the then to keep up; If the then line is written, then there is no problem.
eg:
if [$gender = Femal]; Then ——-right.
if [$gender = Femal]
Then ——————————-right.
if [$gender = Femal] then ——-wrong. The then front is less; Resolution.
Prompt for error message:
Syntax error near unexpected token then
Similarly, there are many error messages such as
Syntax error near unexpected token fi, etc. are caused by this.
Be sure to keep up with then after 5.if. Similarly
Be sure to keep up with then after Elif.
Otherwise prompt for error message:
Syntax error near unexpected token else
1 if statement followed by then, and preceded by a semicolon;
2 space is very important, the shell will think that the space before a command, if A=3 think is an assignment operation, if written a = 3, then think of a as a command this= ' ls-l |grep ' ^-' | Wc-l '
3 The operator should be separated by a space, such as test! -D $, of which! And-D will be separated by a space
A space is an important separator in command resolution
6. There must be a space between the command and subsequent arguments or objects
If [-X "~/workspace/shell/a.sh"];then
A null Gecay indicates whether the string immediately following it points to an executable file name, otherwise the test-X "~/workspace/shell/a.sh" is not empty.
7. The symbol ' $ ' of the variable value and the variable or parenthesis behind it cannot have spaces