/*************************************** ******************************
* Author: Samson
* Date: 08/01/2013
**************************************** ****************************/
BASH Shell script programming learning summary:
Variable:
(1) environment variables: can be modified;
(2) internal variables: provided by the system and cannot be modified;
$ #: Get the number of parameters
$? : ShellProgramReturn Value of shell execution internally
$0: shell program name
$1 ~ $9: parameter 1 ~ 9 value
$ *: String composed of all parameters
(3) User variables: defined by the user during shell writing;
Note: When a user variable is defined in shell, there cannot be spaces before and after the value assignment number. For example, var1 = "test1"
Several shell scripts are executed:
(1) shell interpreter shellscriptname. Sh. In this case, the shellscriptname. Sh does not require the X execution permission;
(2) execute:./shellscriptname. Sh directly in the shell script directory. The premise of this method is that the shellscriptname. Sh file has the X execution permission;
Expression comparison:
The command syntax is as follows:
Test expression
Or
[Expression]
The test command supports the following four types of comparison:
(1) operators in the expression for string comparison:
= Equal
! = Not equal
-Whether the length of N string is greater than 0
-Whether the Z string is equal to 0 or null
(2) Operator in numeric comparison expression:
-Equal EQ
-Ge> =
-Le <=
-Is ne not equal
-Whether the GT is greater
-Lt is less
(3) Operator in file operator expression:
-D whether the file is a directory
-F: whether the file is a common file
-Whether the read permission is set for the R File
-S file length is greater than 0
-W file write permission
-Whether the X file has the execution permission
-E: whether the file exists
(4) Operators in logical operators 'expression:
! Reverse a logic expression
-A performs and operates on two logical expressions.
-O: executes or operates on two logical expressions.
Judgment statement:
If [expression]; then
Statements
Elif [expression]; then
Statements
Else
Statements
Fi
Branch statement:
Case $ varname in
Str1 | str2)
Statements ;;
Str3 | str4)
Statements ;;
*)
Statements ;;
Esac
Loop statement:
(1)
For curvar in list
Do
Statements
Done
(2)
While expression
Do
Statements
Done
Until expression
Do
Statements
Done
Break statement: terminates a repeating loop.
Exit statement: Exit A shell program.
Function:
Func ()
{
Statements
}
Call: func param1, param2, param3
Load another shell program in a shell script:. card_error.sh