1. Shell program Exercise: Create a Dir folder and create a cd.c file in the Dir folder
First VIM hello.sh
2. Variable definitions and references in the shell
(1) Definition and initialization of variables. A shell is a weakly typed language (a variable in a language is a strongly typed language if it has a definite type), a variable with no explicit type is a weakly typed language, and a different C language. Defining variables in shell programming does not require a type, nor is there a concept of type.
(2) Variable definition can be initialized, use = to initialize the assignment value. The value assigned in the SHELL = There cannot be spaces on either side.
Note: The shell is very concerned about the syntax, very strict. A lot of places have to be empty or must have, and can not arbitrarily have no spaces.
(3) Variable assignment, the variable can be assigned again after the value, the new assignment will overwrite the old assignment. The shell does not deliberately distinguish between the definition and assignment of variables, anyway, each variable is a symbol, the value of this symbol is the last value assigned to him.
(4) Variable reference. A variable referenced in the shell must use the $ symbol, and the $ symbol is the variable dereference symbol.
Note: The $ symbol is followed by a string, and the string is parsed as a variable. If the string itself is undefined, execution does not give an error, but instead resolves the variable to null. In other words, a variable that is not defined in the shell is actually a variable that is defined and assigned an empty value.
Note: Variable references can be $var or ${var}. The difference between the two is that in some cases you can only use ${var} and not simply $var
3. The difference between a shell without references, single quotes, and double quotes
(1) using strings in the shell can be used without double quotes. You can also have a space, but the flaw is not output "or other escape characters.
(2) The shell can also use single quotation marks to represent strings, which are also used directly, and cannot output escape characters.
(3) Single quotes: completely literal substitution (cannot contain single quotation marks itself)
(4) in double quotes:
$ plus variable name to take the value of the variable
Anti-quotation marks still indicate command substitution
\$ $ literal Output $ symbol
The literal value of \ ' representation '
The literal value of \ "represents"
\ \ denotes the literal value of \
In addition to the above, there is no special meaning in front of other characters, only the literal value.
(vii) Shell programming learning