Local variables:
Scoped for the entire bash processCopy the code
Local variables:
Scope is the current code segmentCopy the code
Environment variables:
Scope defines a variable for the current shell process and its child set export variable name. Set can be omittedCopy the code
Variable name:
The value can contain only letters, digits, and underscores (_), and cannot start with a digit. 2. Do not have the same name as any existing environment variable in the systemCopy the code
Position variable:
At $1, $2,... $1 for the first parameter,$2 for the second parameter... Shift removes variablesCopy the code
Variable substitution:
A =123456456789 echo ${a:2} 3456456789 Echo ${a:2} 3456 Echo ${a:2:4} 3456 Echo ${a#123} 3456 Echo ${a#123} Echo ${a#*6} echo ${a##*6} 789 echo ${a%6*} 789 echo ${a%6*} 12345645 echo ${a%%6*} The following command output is displayed: 12345 Variable replacement does not change the value of the variableCopy the code
Special variables:
$? Execution status of the previous command return value Program execution, there may be two types of return value program execution result program status return code (0-255) 0: correct execution 1-255: Wrong execution, $1 is the first parameter passed to the shell script. $2 is the second parameter passed to the shell script. $@ is the list of all parameters passed to the script Is a single string that displays all parameters passed to the script. Unlike position variables, parameters can be more than 9. $$is the current process ID of the script. Is to display the exit status of the last command, 0 indicates that there is no error, Basename $0 Extract the name of the script unset variable name Cancel the variable set Check the variables in the current shell printenv or env or export Check the environment variables in the current shell variable name 1=$variable name 1: (path or character) adds the contents of parentheses to variable 1Copy the code