Shell login mode, shell arithmetic operation, Shell logic operation, shell condition test, Shell selection statement
Shell programming in the first line indicates the path of the shell type to be executed
e.g #/bin/bash
1. Shell Login Method
Interactive login:/etc/profile--/etc/profile.d/*.sh--/~/.bahsh_profile--~/.BASHRC--/ETC/BASHRC
Non-interactive login: ~/.BASHRC--/ETC/BASHRC--/etc/profile.d/*.sh
2. Shell arithmetic operations
(1) Operation symbol:
+ Add
-Sub
* Mul
/div
% remainder
(2) Four ways to implement arithmetic operations
A. Let varname=expression
Let varname=2+3, let varname=2*3
B. varname=$[expression]
VARNAME=$[5*6]
C. varname=$ ((expression))
varname=$ ((2+3))
D. varname=$ (expr arg1 arg2 arg3 ...)
varname=$ (expr 2 + 3)
3. Logical operation
&& Logical AND
|| Logical OR
! Logical not
4. Condition Testing
Determines whether an expression is true, completed by a test statement
Test command
Test EXPRESSION
[EXPRESSION]
[[EXPRESSION]]
Test comparison symbols
Numerical
-GT great than
-lt less than
-eq equal
-ne Not Equal
-ge great than or equal
-le less than or equal
e.g Test 2-eq 2, [4-ge 3]
String
= = Strings is equal
> Strings is great
< strings is less
! = strings is not equal
-Z "string": test whether the string is empty, the vacancy is true
-N "string": test whether the string is not empty, not empty is true
File test
TEST-E file test files are present
5. SELECT statement
If-then
If COMMAND
Then
COMMAND
If-then-else
If COMMAND
Then
COMMAND
If-then-elif-then-else
If COMMAND
Then
COMMAND
Elif
Then
COMMAND
...
Else
COMAND
Seven. Shell script programming