1.shell of basic types:
Expression Type: Use the keyword expr stated.
Statement format: var = `expr $ a - $ b`
Related operation symbol: +, -, *, /,%.
Pit: Be sure to note the space, the space omit some places will cause a syntax error, as well as the escape operator character, such as *
Numeric types: the right of the equal sign using a digital variable declaration.
Statement format: a = 10
Related operators: -eq: equality, -ne: are not equal, -gt: detecting whether the number is greater than the left right, -lt: detecting whether the number is less than the left right, -ge: detecting whether the number is greater than the left equal to the right, -le: detecting the number is less than equal to the left of the right
Pit: Only for digital type
String Type: single or double quotes drawn.
Statement format: a = "abc"
Related operators:! =, =, - z, -n, $
Pit: only applies to string types
File Type: Use enclosed by double quotes. String type is similar, but with / No.
Statement format: file = "/ home / abc"
Related operations: too much. . . Major three -r: detecting whether read, -w: detecting whether a write, -x: detecting whether an executable, -s: detecting whether empty, -e: detecting whether a file exists.
Detailed examples can be found in the rookie tutorial species: https://www.runoob.com/linux/linux-shell-basic-operators.html
2. Process Control
for loop
for var in item1 item2 ... itemN do command1 command2 ... commandN done
while loop
while condition do command done
The above cycle support continue and break statement
if else
if condition1 then command1 elif condition2 then command2 else commandN fi
Pits: the form [$ a == $ b] the expression inside the brackets in space can not be omitted.
There may use the test command to omit the brackets
Example:
= 100 num1 num2 = 100 IF Test $ [num1] - EQ $ [num2] the then echo 'two equal number! ' The else echo ' two numbers are not equal! ' Fi
3. The function uses ------ stay pit