Shell's export command


SHELL is an interface program used by users to conveniently control the [operating system].
For the [operating system], this interface program is like a shell wrapped in it: SHELL

----------------

The basic command of the shell: export is explained below

-----------------

Bash has several commands that comes with the shell (ie built inside the bash shell).

When you execute a built-in command, bash shell executes it immediately, without invoking any other program.

Bash shell built-in commands are faster than external commands, because external commands usually fork a process to execute it.

In this article let us review some useful bash shell builtins with examples.

1. Bash Export Command Example

export command is used to export a variable or function to the environment of all the child processes running in the current shell.

export varname=value

# exports a function in the current shell.
export -f functionname

It exports a variable or function with a value.


“env” command lists all the environment variables. In the following example, you can see that env displays the exported variable.
$ export country=India

$ env
SESSIONNAME=Console
country=India
_=/usr/bin/env


“export -p” command also displays all the exported variable in the current shell.


---------------------

===============

How do I use export command under a Linux or Unix-like operating systems to set variables on a bash shell?

You can export shell variables using the export command.

Syntax

The syntax is as follows:
export VAR


You can assign value before exporting using the following syntax:
export VAR=value


OR

VAR = value

export VAR


The export command will marks each VAR for automatic export to the environment of subsequently executed commands i.e. make the local shell variable VAR global.

Examples

To make the local shell variable called PATH type the following:
### export PATH ###
export PATH=$PATH:/usr/local/bin
echo "$PATH"


Set a new EDITOR variable:
export EDITOR=/usr/bin/vim



You need to add export statements to
               ~/.bash_profile or
               ~/.profile or
               /etc/profile
file.

This will export variables permanently:
$ vi ~ / .bash_profile


Sample file
PATH=$PATH:$HOME/bin
export PATH
 
# set vim as a text editor
export EDITOR=/usr/bin/vim
 
# set colorful prompt
export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
 
# set java_home
export JAVA_HOME=/usr/local/jdk


To see all a list of all exported variables and functions, enter:

$ export -p











-
15 Useful Bash Shell Built-in Commands (With Examples)
http://www.thegeekstuff.com/2010/08/bash-shell-builtin-commands/


Use export Command in Linux / Unix
https://www.cyberciti.biz/faq/linux-unix-shell-export-command/









-

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326295705&siteId=291194637