When we use the operating system, we will know that the main function or most function of the set command in the system is to display the existing shell variables in the system, and set the new variable values of the shell variables. When changing shell features with set, the + and – symbols turn off and on the specified mode, respectively. The set command cannot define new shell variables. To define new variables, use the declare command in the form of variable name = value.
Command options
Define variables
Use the declare command to define a new environment variable, tools.
$DECLARE Tools ='VScode'Copy the code
Then use the set command to output the newly defined variable as an environment variable.
Set it to the environment variable $set -a toolsCopy the code
After this command is executed, a new environment variable is added. You can run the env command and grep command to display and search for the environment variable Tools respectively.
# display environment variable value $env | grep toolsCopy the code
After the command is executed, the value of the queried environment variable is displayed.
Use the set/env/export distinction
[escape@localhost ~]$name="EscapeWen" [escape@localhost ~]$echo $name EscapeWen # No corresponding value [escape@localhost ~] $env | grep name # set after the completion of the shell variables have corresponding values [escape @ localhost ~] $set | grep name EscapeWen # corresponds to the value of the Using the export is not exported [escape @ localhost ~] $export | grep name # use expor export, In the user variables should be able to find it [the escape @ localhost ~] $export aaa [escape @ localhost ~] $env | grep aaa EscapeWenCopy the code
Precautions for Use
You can use the unset command to clear environment variables. Note that variables set by set, env, and export can be cleared using unset.
TEST [escape@localhost ~]$export TEST=" TEST "[escape@localhost ~]$unset $TESTCopy the code
Use the readonly command to set the read-only variable.
[escape@localhost ~]$export TEST=" TEST "[escape@localhost ~]$readonly TESTCopy the code