(Big podium: the first in-country it online education hybrid adaptive Learning)
The variables are familiar, but what are the types of these variables, and what are the differences in the use of the specific usage? This article is organized to share to you:
First, Bash Variable Type:
Local variables
Local variables
Environment variables
Positional variables
Special variables (built-in)
second, local variables:
Varname=value: Scopes are available for the entire bash process;
Variable Naming conventions:
1. Can only contain letters, numbers and underscores, and start with letters and underscores
2. It is best not to duplicate the system's existing environment variables
3. See the meaning of the name
third, local variables:
Local Varname=value: Scope is the current code snippet;
iv. Environment variables:
The scope is the current shell process and its child processes and cannot affect its parent process;
Export Varname=value, if the variable is already defined, it can only be exported varname with the variable name, i.e.
1. Export Varname=value
2. Varname=value
Export VarName
The script launches a child shell environment variable when the command is executed:
Scripts that are automatically executed by the system (not command-line startup) require a self-defined environment variable;
Five, Position variable:
$1,$2,$3, ...
Cat first.sh Test.txt Hello
$1:first.sh
$2:test.txt
$3:hello
Shift: kicks off parameters
Shift N: kicks off n parameters and kicks off a parameter by default
vi.. Special variables:
$?: The return value of the previous command execution state:
There are two possible types of return values for program execution:
1. Program execution Results
2. Does the program state return (0-255)
0 to perform the correct
1-255 Execution Error (1,2,127 system reservation);
$#: Gets the total number of parameters in the current shell command line
$*: Gets all the parameters of the current Shell "$ ..., under IFS control
[Email protected]: All parameters of this program "$1″" $2″ "$3″" ... ", not controlled by IFS
$ A Gets the file name of the currently executing shell script
$n gets the nth parameter value of the currently executing shell script, n=1..9
$$ gets the current shell's process number (PID)
$! PID that executes the previous instruction
The Linux system details the variables in Linux bash