The difference between several loops:
until loop, as long as the specific condition is false, the until statement will be executed.
The while loop will execute the
for loop as long as the specified condition is true. The “for” loop always receives a certain type of word list after the “in” statement.
The meaning of i++ is actually i+1
double parentheses:
1. echo $((16#5f)) The result is 95 (hexadecimal to decimal)
2. Redefine the variable value, such as a=5; ((a++)) Yes Redefine $a as 6
numerical comparison parameters:
Is equal to the [-eq]
Greater than or equal to [-ge]
Is greater than [-gt]
Less than or equal to [- le]
Less than [-lt]
Is not equal to [-ne]
Greater greater than greater
equal equal to equal
less less
than than
read Command function:
read a line from standard input, and put each line of input The value of each field is assigned to the shell variable
parameter:
-a followed by a variable, the variable will be considered as an array, and then assign a value to it, the default is to use a space as the separator.
-d is followed by an identifier. In fact, only the first character after it is useful. As a sign of the end, an example will be given.
-p is followed by prompt information, that is, the prompt information is printed before input.
-e Command completion function when inputting.
-n is followed by a number to define the length of the input text, which is very practical.
-r Shield. If there is no such option, it will be used as an escape character. If there is, it will be a normal character.
-s Quiet mode, no longer display on the screen when entering characters, such as entering a password when logging in.
-t followed by the number of seconds, defines the waiting time for input characters.
-u followed by fd, read from the file descriptor, which can be newly opened by exec.
-z judge the value of the variable, whether it is empty; zero = 0
- The value of the variable, is empty, returns 0, is true
- The value of the variable, not empty, returns 1, which is false
-n Determines whether the value of the variable is empty or not name = name - The value of the variable, if it is empty, returns 1, which is false
- The value of the variable, non-empty, returns 0, and is true. The
positional parameter variable is a standard number:
$0 is the program name, $1 is the first parameter, $2 is the second parameter, and so on, until the ninth parameter $9.
-z judge the value of the variable, whether it is empty; zero = 0 - The value of the variable, is empty, returns 0, is true
- The value of the variable, not empty, returns 1, which is false
-n Determines whether the value of the variable is empty or not name = name - The value of the variable, if it is empty, returns 1, which is false
- The value of the variable, non-empty, returns 0, is true
|| and && usage:
logical OR, only the previous execution of || will execute the subsequent
logical AND, and only the previous execution of && will execute the latter
The shell special variable
$0, the file name
$n of the current script, is passed to the parameter of the script or function. n is a number, indicating the number of parameters. For example, the first parameter is $1 and the second parameter is $2.
$#The number of parameters passed to the script or function.
$ All parameters passed to the script or function.
$@ All parameters passed to the script or function. When enclosed in double quotes (" "), it is slightly different from
$. $? The exit status of the previous command, or the return value of the function.
$$Current Shell process ID. For Shell scripts, it is the process ID where these scripts are located. The difference between $* and $@. Both $ and $@ indicate all parameters passed to the function or script. When not enclosed by double quotation marks (" "), they all end with " All parameters are output in the form of $1" "$2"… "$n". But when they are enclosed in double quotation marks (" "), "$ "will take all the parameters as a whole, and output all the parameters in the form of "$1 $2… $n"; "$@" will separate each parameter to "$1" "$2"… "$n" All parameters are output in the form of. ${#P_array[ ]} What does this mean in the shell? Among them (P_array is the name of the array) gets the number of array elements: ${#arrayname[@]}
Get an element in the array: $arrayname[index]
Modify an element in the array: arrayname[index]=new value
Get all the elements in the array: ${arrayname[ ]}
function:
return value: usage of
result result= $(db1) #Save the output of the function to the variable
echo "The new value is $result" #Output variable (that is, the output of the output function) result=$(addem 10 15) #pass to the function addem Two parameters, and then save the execution result of the passed parameters to the variable result
echo "Te new value is $result" #output the result saved in the variable result