Shell之export指令ITeye - 凯时娱乐


2019年03月26日10时08分06秒 | 作者: 瑞渊 | 标签: 操作系统,一个,接口 | 浏览: 2711

SHELL 是用户用来便利控制【操作系统】的一个接口程序。

下面临 shell 的根本指令:export 进行解说


Bash has several commands that comes with the shell (i.e 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

“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.


The syntax is as follows:
export VAR

You can assign value before exporting using the following syntax:
export 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.


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

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

Sample file
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)

Use export Command in Linux / Unix