Shell之export命令
程序员文章站
2022-06-01 17:21:26
...
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/
-
上一篇: 模块化,轻量级的JRE:并非谣传 JavaFXQt公告.netSUN
下一篇: 好吃的枣子有哪些呢