Does the bash test have a grammar test
Bash-n file.sh
Script execution in debug mode
Bash-x file.sh
Defining global variables in the shell
Export date= ' DATE +%y%m%d '
Arithmetic operators in the shell
A=3
B=4
If you use c= $A + $B to represent the addition of strings, the result is 3+4
1. Let arithmetic operation expression
Let c= $A + $B
2. $[arithmetic operation expression]
c=$[$A + $B]
3, $ ((arithmetic operator))
c=$ (($A + $B))
4. Expr arithmetic operator, with spaces between expressions, and using command references
c= ' expr $A + $B '
Conditional test in Shell
1, integer test (binocular operation, compare two numbers, usually variables and numbers or variables and variables)
expression [$A-eq $B] (command test method, note space)
[[$A-eq $B]] (keyword test method)
Test $A-eq $B (Tests command testing method)
-GT greater than
-lt less than or equal to
-ne Not equal to
-eq equals
-ge greater than or equal to
-lt less than
Note: There is no need to use [] in addition to the above-mentioned judgment when testing.
such as: if grep "^ $USERNAME \>"/etc/passwd; then can be directly judged without using []
2. File test
-e file: Test files exist
-F File: Test files are normal files
-D File: Test whether the files are directories
-R File: Tests whether the current user has read access to the specified file
-W File: Tests whether the current user has write access to the specified file
-X file: Tests whether the current user has execute permissions on the specified file
such as: if [-f/etc/inittab] (note space)
Exit # define Exit status code
Bash Variable type
Local variable (local variable) "Scope is current shell"
Environment variable "Scope is current shell and child shell"
Positional variables
$ $
Shift N (kicks the first n position variables)
Special variables
$?: previous command execution status
$#: Number of parameters
$*: Parameter list
[email protected]: parameter list
This article from "Liang Childe" blog, please be sure to keep this source http://iyull.blog.51cto.com/4664834/1884528
Fundamentals of Linux Foundation--bash programming