Embedded system development Xiaobai study notes(9)

Last review

Embedded development Xiaobai study notes(8)

Embedded system development tools (continued from the previous issue)

shell variable type

(4) Variable expression

1. An expression in the shell program of test, usually used in the structure of flow control for, while, until, if, use the test command to determine the existence and nature of the file, and the relationship between the variables.
Syntax: test<expression>
if <expression> is established, test returns 0, otherwise it returns a non-zero value.
2. String comparison (the comparison is the length)
(1) -z<string> judges whether the string length is equal to 0, and returns 0 if it is equal to 0.
(2) -n<string> determines whether the length of the string is greater than 0, and returns 0 if it is greater than 0.
(3) <string1>=<string2> judge whether the two strings are the same, if they are the same, return 0, and there must be spaces on both sides of the equal sign to judge using ==.
Insert picture description here
(4) <string1>!= <String 2> Judge whether the two strings are the same, if they are different, it will return 0.
3. Comparison of the two values
Logical operation, you can perform and/or, and use
file operations in conjunction with other conditions , such as whether the file exists the status
4, the digital comparator (comparing the size, meet the condition returns 0)
<Numerical expression 1> <operator> <numerical expression 2> (both sides of the operator include a space)
(1) <string> - eq <string> judges whether the two are equal, if they are equal, it returns 0.
(2) <string> -ne <string> judges whether the two are not equal, if they are not equal, it is yes, returns 0
(3) <string> -lt <string> Determine whether the former is less than the latter, if it is less than yes, return 0
(4) <string> -le <string>

(6) <string> -ge <string> judge whether the former is greater than or equal to the latter, if it is greater than or equal to the latter, it is yes, and return 0
Insert picture description here

5. File operation The
file test expression is to test the file operation logic
(1)-e: whether the object exists, the return value is 0.
(2) -d: the object exists and is a directory, the return value is 0.
(3 ) -F: If the object exists and is a file, the return value is 0.
(4) -L: If the object exists and is a symbolic link, the return value is 0.
(5) -r: If the object exists and is readable, the return value is 0.
-s (. 6): the object is present and non-zero length, then the returned value is 0
(7) -w: objects and writeable exists, return the value 0.
(8) -x: an executable object exists and , The return value is 0.
(9)! : Negation of test conditions. (Separated by a space from the above symbols)
Insert picture description here
6. Logic test is
often used for logic test. The <expression> has:
(1)! <expression>: <expression> does not hold
(2) <expression 1> -a <expression 2>: <expression 1> and <expression 2> hold simultaneously
(3) <expression> -o <expression Formula 2>: <Expression 1> or <Expression> is established

shell statement flow control statement

1. Conditional control: if, case structure
(1) if conditional statement
Usage:
if<discrimination order>;
then{command list 1}
then{command list 2} //else statement can omit
fi
2. Loop control: for, while , Until and other structures
Note: In the shell, the conditional judgment statement can use if conditional statement and case conditional statement. The case statement has more options.

Guess you like

Origin blog.csdn.net/m0_52251623/article/details/114995225