Variable: the PATH environment variable SHELL current shell UID user's UID
GID user GID the USER username $ 1 .. $ 9 positional parameters $ # number of positional parameters $ * all positional parameters ( as a single string ) $ @ all positional parameters ( each
As a separate string of ) the LANG current language setting system sets variable RANDOM removable random number
Weak references "" most of the characters are treated as ordinary characters, there are exceptions \, $, ` three special characters
* Matches any character of any length? Matches any single character [] : matches any single character within a specified range of several special format [az] any single letter [0-9] according to any
Is intended a single digital [a-z0-9] any of a number or letter
[: upper:] capital letters [: lower:] lowercase letters
Define an environment variable: DECLARE the -X-var_name = value or export var_name = value
Define a variable shaping declare -i var_name = value
+ =, - =, * =, / =,% = you need to use let commands described example let var + = 1 let var ++
Definition of a variable: mypath = "/ etc / sysconfig / Network-scripts /"
echo $ {mypath: 5} offset . 5 characters displayed
echo $ {mypath: 5: 5 } offset . 5 characters taken . 5 characters.
echo $ {mypath: -10} Remove the last 10 characters
Determining whether the string is equal to: [[ "$ mypath" == "KK"]] == sides should have a space, and the characters must be enclosed in quotes
Determine whether the specified string is empty [[-z "$ mypath"] ] is empty True, not empty and false
[[-N "$ mypath"] ] Determines if the specified string is empty is false, not true empty
[-E / etc / sysconfig] determines whether a file exists -a and -e is a mean, there are similar -d exists and directory -f exists and an ordinary text file -r
-S member exists and is readable file exists and is not empty -w -x file exists and is writable and executable file exists
while special trip traversal of the file usage: while Read I; do echo $ I; DONE </ etc / the passwd
Definition of a function: f_name () {.. function body ..} Note that the function as much as possible with local variable is defined
Array: Continuous memory space to store multiple elements, the entire array is only one name
Array index: number from 0 start $ {ARRAY_name [INDEX]}
Declare the array: DECLARE -a NAME
Only a time assignment element: NAME [0] = Jerry NAME [. 1] = Bob
Once all elements of the assignment: NAME = ( "val1" "val2" "val3")
Assigning only certain elements: NAME = ([0] = "VAL1" [. 3] = "the VAL3")
A reference element in the array: $ {ARRAY_NAME [the INDEX]}, Note: reference only to the name of the array. It is a reference to the small labeled 0 element
Length of the array ( the number of elements in the array ): $ {# ARRAY_NAME [* ]} or $ {# ARRAY_NAME [@]}
The maximum take ten random numbers
#!/bin/bash
declare -a rand
declare -i max=0
for i in {0..9}; do
rand[$i]=$RANDOM
echo ${rand[i]}
[ ${rand[$i]} -gt $max ] && max=${rand[$i]}
done
echo "MAX: $max"
Reproduced in: https: //www.cnblogs.com/linuxboke/p/5664841.html