Use of shell (1) variables in Linux, linuxshell
One Variable
Echo $ a: output variable a. If it does not exist, a variable a is created.
Unset a: Cancel variable
1.1 environment variables:
Env: View descriptions of environment variables and common variables
HOME: Your main folder
HISTSIZE: Number of historical commands that can be recorded by the System
PATH: PATH of the execution file query
LANG: modifiable language family
Set: view all variables, including environment variables and custom Variables
PS1: Command Prompt
Export: You can convert custom variables to environment variables.
Language: locale
Keyboard reading, array, and Declaration of 1.2 Variables
Read: read variables from keyboard input
For example, read-p "please input your name:"-t 30 name (after the command is executed, please input your name:) your input value will be included in the variable name, if this parameter is not entered for more than 30 seconds, the system will be disqualified
-P: Followed by a prompt
-T: the number of seconds that can be followed.
Declare/typeset: declare the type of the Variable
Declare [-aixr] variable name
-A: defines variables of the array type.
-I: defines integer variables.
-X: Change the variable after the parameter to the environment variable.
-R: Set the variable to read-only.
Note: The default variable type is "string"
Array: array variable type
Delete, replace, and replace variable content
Variable setting method
$ {Variable # keyword} if the variable content matches the keyword from the beginning, the minimum data that matches the keyword is deleted.
$ {Variable ## keyword} if the variable content matches the keyword from the beginning, the longest matching data will be deleted.
$ {Variable % keyword} if the variable content matches the keyword from the forward data, the minimum data that matches the keyword is deleted.
$ {Variable % keyword} if the variable content matches the keyword from the end to the forward data, the longest matching data is deleted.
$ (Variable/old string/New String) if the variable content matches the old string, the first old string will be replaced by the new string
$ {Variable // old string/new string} if the variable content matches the old string, all old strings will be replaced by the new string