Open In App

export command in Linux with Examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

export is bash shell BUILTINS commands, which means it is part of the shell. It marks an environment variables to be exported to child-processes.

Export is defined in POSIX as The shell shall give the export attribute to the variables corresponding to the specified names, which shall cause them to be in the environment of subsequently executed commands. If the name of a variable is followed by = word, then the value of that variable shall be set to the word.

In simple terms, environment variables are set when you open a new shell session. at any time if you change any of the variable values, the shell has no way of picking that change. The export command, on the other hand, provides the ability to update the current shell session about the change you made to the exported variable. You don’t have to wait until new shell session to use the value of the variable you changed.

Syntax :

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

Options of export command

1. Without any argument : To view all the exported variables.

EXAMPLE :

export_1

2. -p : To view all exported variables on current shell.

SYNTAX :

$ export -p

EXAMPLE :

export_2

3. -f: It must be used if the names refer to functions. If -f is not used, the export will assume the names are variables.

SYNTAX :

$ export -f function_name

EXAMPLE : To export shell function:

export_3

Note: Bash command is used for showing that in the child shell, the shell function got exported.

4. name[=value]: You can assign value before exporting using the following syntax.

SYNTAX :

$ export name[=value]

EXAMPLE : To set vim as a text editor

export_4

Note: No output will be seen on screen, to see exported variable grep from exported ones is used.

5. -n: Named variables (or functions, with -f) will no longer be exported.

SYNTAX :

$ export -n variable_name

EXAMPLE :

export_5

Note: No output will be seen on screen, to see exported variable grep from exported ones is used.


Last Updated : 15 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads