1, the variable with = assigned value when the left cannot have spaces. For example , UserName =nihao returns userName: Command not found . Because this place username as a command to deal with. The right approach is to Username=nihao.
Careful is the most important thing, such a small problem is really hard to find. However , when using the Vim editor, the highlight command is white and the variable is green.
2. When reading user input with the read- p command, the variable name after the prompt after-p must have a space. For example read-p "Input your Name:" Name outputs input your name:name, at which time the user's input is not given as expected. The correct approach is to Read-p "Input your Name:" Name (the space before name is required).
3, when using = = for string comparison, = = must have a space before and after, if not, it is always true. For example:
"1" = = "2" ]; Then echo "Xiangdeng" Else echo "Budeng" fi
Only output Xiangdeng, must be [["1" = = "2"]] to [["1" = = "2"]].
4, [[]] and [] generally can be replaced, but must be used in =~ [[]]
Small problems in Shell programming