Case: Flow control statements
• Loop Statement For...done statement
• Use (()) to extend the method of using arithmetic operations in the shell
• Looping statement nesting
• Jump out of the loop: Break and Continue
shift parameter Left SHIFT command
How to use functions in shell
Case statement; Select structure
Case SWITCH in
VALUE1)
Statement
.....
;;
Value2)
Statement
.....
;;
*)
Statement
.....
;;
Esac
#! /bin/bash
echo "***********************************"
echo "Please select your operation:"
echo "1 Copy"
echo "2 Delete"
echo "3 Backup"
echo "4 Quit"
echo "**********************************"
Read-p "Please select:" Op
Case $op in
C|C)
echo "Your selection is Copy"
;;
D|D)
echo "Your selection is Delete"
;;
B|B)
echo "Your selection is Backup"
;;
Q|Q)
echo "Quit"
;;
*)
echo "Invalide selection"
====================================================
Loop: Enter condition, exit condition
For statement
For variable in list: do
Loop body
Done
The declare command is a built-in command of Bash, which can be used to declare shell variables
The declare command allows variables to be assigned at the same time when declaring variable types
-R: Read-only
-I: Integer
-F: function
-A: Array
-X: Declares a variable to be exported as an environment variable of the script
While Loop statement
While condition
Do
Command
Done
====================================================
using (()) to extend the use of arithmetic operations in the shell
The previous method
When using "[]", you must ensure that there is a space between the operator and the arithmetic. Arithmetic can only be done with: expr command
The double-Brace "(())" Structure statement is an extension of the arithmetic and assignment operations in the shell.
Grammar:
(expression 1, expression 2 ... ))
Characteristics:
1, in the double bracket structure, all expressions can be like C language, such as: a++,b--, etc. A=a+1
2. In a double-brace structure, all variables may not be added: "$" symbol prefix.
3, the double parenthesis can carry on the logical operation, arithmetic
4. Double bracket structure expands the FOR,WHILE,IF condition test operation
5. Support multiple expression operations, separated by commas "," between the expressions
=====================================================
Loop statement nesting:
Jump out of the loop: Break and Continue
Break: Jump out of the loop
Continue: Skip this cycle for the next cycle
Shell Learning to practice more
Linux-shell case-for-while-Double Brackets-loop nesting-break-continue