To complete this chapter, you can do the following things:
Use the Shell's alternative function, including variable substitution, command substitution, and tilde substitution.
Set up and modify shell variables.
Pass local variables to the environment.
Make the variable take effect on the child process.
Explains how the process was created.
7.0 Shell substitution function
There are three types of substitutions in the shell:
Variable substitution
Command substitution
Wave substitution
The alternative is to speed up the typing and execution of the command line
7.1 Shell Variable Storage
There are two memory areas in the shell for storing shell variables: Local data regions and environments. When a new variable is defined, the memory is assigned to the local data region, where the variable is the current shell private, often called a local variable, and no subsequent subprocess will access the local variables. However, a child process can access variables that are transferred to the environment.
During your login process, there are several special shell variables that are defined. Most of these variables are stored in the environment: some variables, such as PS1 and PS2, are stored in the local data area. The values of these variables can be changed to customize your terminal features.
The env command can display all variables currently stored in the environment, such as:
$ env
Manpath=/usr/share/man:/usr/contrib/man:/usr/local/man
Path=/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/usr/local/bin
Logname=user3
Erase=^h
Shell=/usr/bin/sh
Home=/home/user3
Term=hpterm
Pwd=/home/user3
Tz=pst8pdt
Edtor=/usr/bin/vi
7.2 Set the shell variable
Syntax: http://www.aliyun.com/zixun/aggregation/11696.html ">name=value
Example:
$ color=lavender? ? ??????? Assign a value to a local variable
$ count=3????????????? ? Assign a value to a local variable
$ Dir_name=tree/car.models/ford? Assign a value to a local variable
$ ps1=hi_there?????????? ?? Change the value of an environment variable
$ set??????????? ????? Show all variables and values
When a user creates a new variable, such as color, the variable is stored in the local data area. When an existing environment variable is given a new value, such as path, the new value replaces the old value in the environment.