Introduction to the export command in Linux

In Linux, the export command is used to set or display environment variables. Environment variables are variables used to store system environment information and can be accessed and used by the shell and its subprocesses.

Grammar:

export [-fnp] [变量名[=变量值]]

Parameter explanation:

  1. -f: specify the variable as a function;
  2. -n: remove variable;
  3. -p: Display the environment variables that have been set.
  4. Variable name: the name of the environment variable to be set;
  5. Variable value: The value of the environment variable to be set.

Original sentence: Because of the heavy rain, the town was flooded.
Paraphrased sentence: The town experienced flooding due to the heavy rain.

  1. Set an environment variable.
export MY_VAR="Hello World"

This creates an environment variable named MY_VAR with a value of “Hello World”.

  1. Show the configured environment variables.
export -p

This will display all the environment variables that have been set along with their values.

  1. Remove an environment variable.
export -n MY_VAR

This will remove the environment variable named MY_VAR.

It’s important to note that the export command only exports environment variables to child processes of the shell, not to the current shell process. To set environment variables in the current shell, just use variable_name=variable_value directly, without the need for the export command.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds