Linux export Command
Learn Linux export Command with examples
Published
- Linux export Command
- export Command Syntax
- export Command Example
- export -p Command
- export -f Command
- export -n Command
- export name[=value] Command
- Single Value assigning before exporting a function
- Export multiple variables before exporting a function
Linux export Command
In Linux, we can use “export” command use Environmental variables are exported in it as child processes.
The existing environment variables are not affected.
The export command helps update the current position of the shell session because of the change we have made with the exported variables.
export Command Syntax
>> export [-f -n] [name [= value] …... ]
>> export -p
export Command Example
>> export
export -p Command
-p is used for enlisting all the names that are being used in the current shell. -n helps in removing the names from the exported list. -f is to export the names as functions.
>> export -p
export -f Command
To export a function, you first need to write a function in your command line with the unique function name. So that we can call the function easily. Once the function is exported, we can easily access it by calling the name of the function.
>> mysite() { echo "webmastercampus.com";}
>> export -f mysite
>> mysite
Here we have used mysite () as the function. In this function, we have just printed the name of our website webmastercampus.com.
After defining the function, we will export the function with the help of the “-f” keyword. Bash function is also exported here.
export -n Command
This feature is used to remove the variable. In this part, we are going to remove “EDITOR.”
>> export –n EDITOR
>> export | grep EDITOR
After applying the first command, you will see that no output is obtained, so for confirmation, we will use the grep command to export the variables if they are present.
export name[=value] Command
export name[=value] you can assign value before exporting using the following syntax.
>> export name[=value]
Single Value assigning before exporting a function
The export command allows us to introduce the value assigning before exporting a function.
>> x =100
>> export x
>> printenv x
Export multiple variables before exporting a function
The export command allows us to introduce the value assigning before exporting a function.
>> x =100
>> y =200
>> z =300
>> export x y z
>> printenv x y z