1. When defining variables, You cannot leave spaces on either side of the = sign.
eg
Gender=femal------------Right
Gender =femal-----------Wrong
gender= femal-----------Wrong
2. Conditional test statement [the symbol is left blank on both sides .]
eg
if [$gender = Femal]; Then-------right.
echo "You are Femal";
Fi
if[$gender ...-----------------------wrong
If [$gender ...----------------------wrong.
3 Conditional test content, if it is a string comparison, the comparison symbol on both sides to leave a space!
eg
if [$gender = Femal]; Then-------right.
if [$gender = Femal]; Then--------wrong.
If [$gender =femal]; Then---------wrong.
4. If if and then are written on the same line, then, notice that then the front should be followed; No problem if then the line is written. (Bash:==,dash =)
eg
if [$gender = = Femal]; Then-------right.
if [$gender = = Femal]
Then-------------------------------right.
if [$gender = Femal] then-------wrong. Then the front is less; No..
Prompt error message:
Syntax error near unexpected tokens then
In the same vein, there are many error messages, such as
Syntax error near unexpected token fi, etc. are caused by this.
5.if must keep up with then. The same elif must follow then.
Otherwise, an error message is indicated:
Syntax error near unexpected token else
1) The If statement is followed by then, with a semicolon in front;
2) The space is very important, the shell will consider a space before the command, if A=3 is considered an assignment operation, if written as a = 3, then will think a is a command this= ' ls-l |grep ' ^-' | Wc-l '
3) The operators should be separated by a space, such as test! -D $, where! And-D will be separated by a space
Whitespace is an important delimiter in command parsing
Shell whitespace issues