set

Display or set shell properties and shell variables

Supplementary instructions

set command is mainly used to display shell variables that already exist in the system and to set new variable values ​​of shell variables. When using set to change shell features, the functions of the symbols "+" and "-" are to turn on and off the specified mode respectively. The set command cannot define new shell variables. If you want to define a new variable, you can use the declare command to define it in the format of variable name=value.

grammar

set(option)(parameter)

Options

-a: Mark modified variables for output to environment variables.
-b: Causes the suspended background program to immediately report the execution status.
-C: The file generated by the redirection cannot overwrite the existing file.
-d: By default, the Shell will use a hash table to remember used instructions to speed up the execution of instructions. Use the -d parameter to cancel.
-e: If the value returned by the command is not equal to 0, exit the shell immediately.
-f: Cancel the use of wildcards.
-h: Automatically record the location of the function.
-H Shell: You can use "!" plus <command number> to execute the commands recorded in the history.
-k: The parameters given by the command will be regarded as the environment variables of this command.
-l: Record the variable name of the for loop.
-m: Use monitor mode.
-n: Only reads instructions without actually executing them.
-p: Start priority mode.
-P: After enabling the -P parameter, when executing the command, the symbolic link will be replaced by the actual file or directory.
-t: Exit the shell after executing subsequent instructions.
-u: When an undefined variable is used during execution, an error message will be displayed.
-v: Display the input value read by the shell.
-x: After executing the command, the command and the parameters will be displayed first.

Parameters

Cancel the parameters that a set has started.

Example

Use the declare command to define a new environment variable "mylove" and set its value to "Visual C++". Enter the following command:

declare mylove='Visual C++' #Define new environment variables

Then use the set command to output the newly defined variables as environment variables. Enter the following command:

set -a mylove #Set as environment variable

After executing this command, the corresponding environment variables will be added. Users can use the env command and grep command to display and search for the environment variable "mylove" respectively. Enter the following commands:

env | grep mylove #Display environment variable values

At this time, after the command is executed, the queried environment variable value will be output.