Bash Variable type:
Environment variables
Local variables (local variables)
Positional variables
Special variables (built-in)
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
Local variables:
Local Varname=value: Scope is the current code snippet;
Environment variable: 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;
Positional variables:
$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
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
Bash:
Reference variable: ${varname}, parentheses can be omitted
Undo Variable:
unset varname
To view variables in the current shell:
Set
Include environment variables and local variables
To view environment variables in the current shell:
1. printenv
2. Env
3. Export
The variables in bash