Environment variable; location parameter variable; predefined variable, environment variable
Environment Variable
Set the environment variable: 1. export variable name = variable value
2. variable name = variable value
Export variable name
(Export variable name = variable value: declare this variable as an environment variable so that all the sub-shells in this SHELL can view and use this variable)
Query variable: env
View process tree: pstree
PATH: path of the system query command
PATH = "$ PATH":/root/sh → PATH variable superposition (temporary)
By default, all environment variable names are in uppercase.
Location Parameter Variable
$ N: n is a number, $0 represents the command itself, $1-$9 represents the first to 9th parameters, and more than 10 parameters are included in braces, such as $ {10}
$ *: This variable represents all parameters in the command line. $ * considers all parameters as a whole.
$ @: This variable also represents all parameters in the command line, but $ @ treats each parameter differently.
$ #: This variable represents the number of all parameters in the command line.
Predefined Variables
$? : The Return status of the Last Command executed. If the value of this variable is 0, it indicates that the previous command is correctly executed. If the value of this variable is not 0 (the specific tree is determined by the command ), the execution of the previous command is incorrect.
$: Process ID of the current process
$! : Process Number of the last process running in the background
Add the command & and run the command in the background.
Accept keyboard input → read option variable name
-P "prompt information": the prompt information is output while waiting for read input.
-T seconds: The read command will remain waiting for user input. You can use this option to specify the waiting time.
-N characters: The read command only accepts the specified number of characters and runs
-S: hides input data, which is applicable to input of confidential information.