Signup/Sign In
PUBLISHED ON: JANUARY 16, 2023

Export Command in Linux

The export command is a built-in feature of the Bash shell on Linux, which allows you to set environment variables that can be accessed by child processes (programs or tasks that are launched from the current shell). These variables store information that is needed by the operating system and certain programs, and the export command allows you to update the current shell session about any changes made to these variables. This means that you don't have to wait until a new shell session is opened to use the updated value of an exported variable.

In simple terms, the export command allows you to modify environment variables and have those changes take effect immediately in the current shell session, rather than having to wait until a new session is opened.

The export command can be used to create new environment variables or to modify existing ones, allowing you to customize your Linux environment to better suit your needs. In this tutorial, we will discuss the export command in more detail and demonstrate how to use it to set and modify environment variables on Linux.

export [-f] [-n] [name[=value] ...] or export -p 

Options of the export command

1. export command Without any argument

If you run the "export" command without any arguments, it will display a list of the environment variables that are currently exported. These are variables that the current shell session and any child processes have access to. Each variable is listed in the format "VARIABLE=value," where "VARIABLE" is the variable's name and "value" is the variable's current value.

export

export command

2. export -p Command

The "export -p" command displays a list of all environment variables, including those that are not currently exported, in a format suitable for setting those variables in a script or another shell session. It displays the exported variables and their values in the same format as when the "export" command is used without any arguments, but it also displays variables that are not currently exported.

The "-p" option prints the variables and their values in a format suitable for use as input for the "source" command or as a script to set the variables in a new shell session.

Syntax:

$ export -p 

export command

3. export -f Command

The command "export -f" is used to export functions from a shell script. It is used to expose the functions defined in a script to the environment, allowing them to be called from other scripts or the command line. The -f flag indicates to the export command that the following argument is a function name.

SYNTAX:

$ export -f function_name 

EXAMPLE: To export shell function:

export command

4. export name[=value] Command

You may use the following syntax to assign an n value before exporting.

Syntax:

$ export name[=value] 

Example: To set vim as a text editor

export command in linux

5. export -n Command

To assess the n value before exporting, use the following syntax.

Syntax

$ export -n variable_name 

Example

export command

Conclusion

an export command is an important tool in Linux that allows you to set and modify environment variables. These variables are used to store information that is needed by the operating system and certain programs and can be accessed by these programs to configure various settings and preferences. By using the export command, you can customize your Linux environment and tailor it to your specific needs and preferences. Whether you are creating new environment variables or modifying existing ones, the export command is a powerful tool for managing your Linux environment.



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.