Shell之export指令ITeye - 凯时娱乐

Shell之export指令ITeye

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


SHELL 是用户用来便利控制【操作系统】的一个接口程序。
关于【操作系统】来说,这个接口程序就象是包在其外的一个壳: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
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/









-
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表凯时娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章