`

Shell之export命令

阅读更多

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/









-
分享到:
评论

相关推荐

    shell 与 export命令

    在这个shell中,可以使用shell命令 或声明变量,也可以创建并运行shell脚本程序。运行shell脚本程序时,系统将创建一个子shell。 此时,系统中将有两个shell,一个是登录时系统启动的shell,另一个是系统为运行脚本...

    export命令 系统设置

    export命令用于将shell变量输出为环境变量,或者将shell函数输出为环境变量。 一个变量创建时,它不会自动地为在它之后创建的shell进程所知。而命令export可以向后面的shell传递变量的值。当一个shell脚本调用并执 ...

    学习笔记《LINUX+SHELL脚本攻略》Sarath Lakshman

    Linux export命令用于设置或显示环境变量。 在shell中执行程序时,shell会提供一组环境变量。export可新增,修改或删除环境变量,供后续执行的程序使用。export的效力仅及于该次登陆操作。 语法 export [-fnp]...

    深入浅出的学习变量(局部、全局、系统、位置、只读变量… set 命令、export 命令、以及如何设置环境变量!)

    ①、首先 使用 set 命令查看所有变量:②、接着 使用 bash 命令 进入当前shell 的子shell 进程:③、然后 使用 pstree -p 来查看进程之间的树状关系图:④、最后 使用 exit 命令退出当前 shell进程:②、全局变量...

    浅析linux环境变量export命令详解

    由host $ export DVSDK=”${HOME}/ti-dvsdk_dm368-evm_xx_xx_xx_xx”引发的问题 ... Linux export 命令 功能说明:设置或显示环境变量。(比如我们要用一个命令,但这个命令的执行文件不在当前目录,

    在rt-thread实时系统上自定义Finsh命令

    在rt-thread实时系统上自定义Finsh命令,在控制台上通过指定的命令控制LED灯的闪烁。

    给Applet签名的Shell脚本

    对打成jar包的applet进行签名的shell脚本,以保证能在页面上... export PATH="/usr/local/jdk1.6.0_29/bin:$PATH" //目的是为了后面的jarsigner命令是调用的jdk里面的jarsigner命令,而不是shell里面的jarsigner命令

    shell编程学习笔记

    shell变量的作用域 可以用export内置命令将局部变量设置为全局变量。 位置变量 用于向shell脚本传递信息。参数相关数目传入脚本,此数目任意多,但只有前9个可以被访问,使用shift命令可以改变限制。...

    centos7下启动springboot项目启动脚本(shell脚本)

    前言:打包好的springboot项目,可以使用java -jar xxx.jar的方式启动。当出现多个springboot项目需要启动的时候,可以使用脚本启动的方式。这在springcloud项目的开发测试阶段尤为有用。...export

    shell中长命令的换行处理方法示例

    前言 考察下面的脚本: ...o ./dist/test....这里在调用 emcc

    Linux crontab定时执行Shell脚本需要执行特定的命令时解决思路

    多方查找发现Shell脚本中的Java命令需要引入环境变量方可正常执行。因此做了一下修改,脚本如下(仅供参考): 1、crontab执行配置 * * * * * cd /项目目录 && ./auto_start.sh >> /log/auto.out 2、Shell脚本 #!/...

    Linux学习(一)———–shell常见命令解析

    我其实对linux并不了解,借这个机会需要系统的整理一下,ros和自动驾驶仿真软件是自动驾驶很有力的辅助工具,在前人的肩膀上,我先看代码,很多是shell脚本,那这里把我遇到的shell脚本中常见的命令进行系统总结一下: ...

    calendar-import-export:导入时将Android日历导出为ics文件,而无需使用Google云

    日历导入/导出 这个应用程式可让您使用ics档案来... 确保Android SDK目录“ platform-tools”和“ tools”在您的PATH中(shell命令export PATH="$ANDROID_HOME/platform-tools/:$ANDROID_HOME/tools/:$PATH ) 用Grad

    runtime-shell:runtimejs 的 Shell 命令

    运行时外壳runtimejs 的 Shell 命令用法: // You must have loaded 'runtimejs' already, that's the argument passed ... // Returns version (only export for now) 命令(从 v0.0.2 开始): 回声清除关机重启ping

    UNIX Handbook

    3.export导出环境变量: 41 4.shift命令: 41 5.shell的参数扩展: 41 6.<<即时文档 42 7.sh调试选项 42 8.time命令测试一个程序执行时间 42 9.expr命令 42 10.if语句判断变量是否为某个值(防止空串...

    sh:自定义全局shell命令

    增加自定义全局shell命令 写法 具体写法参考setNpmRegistry 可执行权限 记得设置可执行权限 chmod +x setNpmRegistry 增加入口 根据实际路径设置 export PATH=$PATH:~/sh 参考文档

    Linux系统编程第06期:从零实现一个shell解释器

    可以在shell交互窗口中执行用于输入的shell命令 实现shell的内建命令:cd、exit、export等 支持管道命令 | 支持进程的后台执行 支持脚本的解析和运行 支持脚本简单的if-else控制语法 支持信号的处理操作

    表情符号术语:使用表情符号代替常用的shell命令

    echo ' export PATH=$PATH:~/emoji-term/bin ' >> ~ /.zshrc 仅在macOS上测试。 支持的命令 系统 表情符号 命令 :raising_hands: 祝福(macOS) :cat: 猫 :calendar: 卡 :optical_disk: 光盘 :speech_...

    hive的安装与配置.txt

    2. 解压安装包:进入/opt目录,使用以下命令解压Hive安装包,并将解压后的文件夹重命名为hive。 ```shell cd /opt tar -zxvf apache-hive-3.1.0-bin.tar.gz mv apache-hive-3.1.0-bin hive ``` 3. 配置环境变量:...

Global site tag (gtag.js) - Google Analytics