Both Shell and python are weak languages to define variable rules: variable name = value
Rules for defining variables in the shell: 1: There can be no spaces on both sides of the equal sign
2: Defining special variables needs to be combined with single quotes or double quotes
3: Defining linux commands requires backticks
Distinguish the differences and similarities between single quotes and double quotes
Shell value use: echo $ variable name
Rules for shell scripts (2):
Parameter passing:
Transfer data to .sh file
Format:
4. Comparison operators
Comparison Operators (Numbers)
-eq compares for equality
-ne Compare unequal
-gt Compare greater than
-ge Compare greater than or equal to
-lt compares less than
-le less than or equal to
String judgment: == , !=
Logical operators -a and -o or !not
((i++)) ((i+=1))
s=$(($s+$i)) s=$[$s+$i] ((s=$s+$i))
5. if statement
①: There is a space after if.
②: There are spaces on both sides of the condition.
③: If there is a variable in the if condition, $ is required, and double quotes are required on both sides of the variable.
④: fi is the end mark.
Case loop statement
①: The first line of case ends with in
②: The value can be a string or a number, if the number range is [0-9]
③: end statement;;
④: esac end sign
for loop
If there are too many list elements use seq mix step max
Notice:
①: mix start data
②: step: interval (number of steps)
③: max end data, if step is 1, it can be omitted
Note:: end sign done
8. while loop
Finish:
①:done
②: While there is a space after the while, also pay attention to the parameters
return value
There is a default return value in the function in the shell
View the return value of the function with "$?"