Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the scope of shell variables?
What is the scope of shell variables?
Shell is a program written in C language, which is a bridge for users to use Linux. Shell is not only a command language, but also a programming language, covering many miscellaneous knowledge points, but it is one of the technologies that cloud computing developers must master. Next, I'll sort out the knowledge about Shell variables for you.

Variables in the Linux Shell can be specified as any data type, such as text strings or numeric values. You can also change the style of the Shell by modifying variables in the Shell.

The Shell supports three ways to define variables:

Variable = value

Variable =' value'

Variable = "value"

A variable is a variable name and a value is a value assigned to the variable. If the value does not contain any white space (such as spaces, tab indentation, etc.). ), then you can use no quotation marks; If the value contains spaces, it must be enclosed in quotation marks. Please note that there cannot be spaces before and after the assignment number =.

The naming standard of Shell variables is the same as most programming languages: variable names consist of numbers, letters and underscores; Must start with a letter or underscore; You cannot use keywords in the Shell (you can view the reserved keywords through the help command).

Shell variables in Linux are divided into system variables and user-defined variables. System variables include $HOME, $PWD, $SHELL, $USER, echo $SHELL and set that displays all variables in the current SHELL.

Shell custom variables include 1) definition variables: variable = value; 2) Undo variables: cancel setting variables; 3) Declare static variables: read-only variables, and be careful not to cancel the setting; They; 4) use export to upgrade the variable to a global environment variable, such as TOMCAT_HOME variable in /etc/profile, and use this environment variable in another /opt/tmp/shell/myShell.sh script.

Shell setting environment variables

Basic grammar:

1) export: variable name = variable value (function description: output shell variable as environment variable)

2) Source: configuration file (function description: make the modified configuration file take effect immediately)

3) echo: $ variable name (function description: query the value of environment variable)

Single line comment: #

Multi-line comments:: <<! What need to comment!

Shell scripts are very suitable for processing plain text data, while almost all configuration files and log files (such as NFS, Rsync, Httpd, Nginx, MySQL, etc. Most startup files in Linux are plain text files. Shell is a skill that operation and maintenance personnel must master, in addition to Linux, information security, Docker container and so on.