linux-shell (7)-Bash variable-user-defined variable

1: What is a variable

        Variables are computer memory units where the values ​​stored can be changed. Using variables can save useful information and let the system know the user's related settings. Variables can also be used to save temporary information.

2: Variable setting rules

       a. Variable names can consist of letters, numbers, and underscores, but they cannot begin with a number. b. In Bash, the default types of variables are all string type. If you want to perform numerical operations, you must specify the variable type as numeric. c. Variables are connected with equal signs. There should be no spaces on the left and right sides of the equal sign. d. If the value of the variable has spaces, you need to use single or double quotes to include. e. In the value of the variable, you can use the "\" escape character. f. If you need to increase the value of the variable, you can superimpose the value of the variable. However, variables need to be enclosed in "$ variable name" in double quotes or included in $ {variable name}. g. If the result of the command is assigned to the variable as a variable value, you need to include the command using backticks or $ (). h. Capitalization of environment variable names is recommended for easy distinction.

    Examples of g 

    Example of f

  Variable view using set command (set can view all variables)

Delete variable unset

3: Classification of variables

User-defined variables

Environment Variables: This type of variables mainly saves data related to the operating environment of the system.

Position parameter variable: This variable is mainly used to pass parameters or data to the script. The variable name cannot be customized and the role of the variable is fixed.

Predefined variables: Variables that have been defined in Bash, variable names cannot be customized, and the role of variables is fixed.

Published 158 original articles · Like 10 · Visitors 20,000+

Guess you like

Origin blog.csdn.net/ab1605014317/article/details/105620622