How to add export statement in a bash_profile file?

旧街凉风 提交于 2019-12-04 16:58:05

问题


I'm trying to learn that if I have to add export statement to set a variable in a bash_profile file . How would I do that ? For example if I have to add export AX = 'name' then should I simply write it at the end of file or do I need to write anything else as well


回答1:


Simply write export AS='name' anywhere in your ~/.bash_profile file:

# Append to the end of the file
$ echo "export AS='name'" >> ~/.bash_profile

# Update shell 
$ source ~/.bash_profile

This first command adds the line you want to the file (or just use a text editor) the second updates the shells with the new variable.




回答2:


There are 2 scenarios:

1. Exporting an independent variable

For example if you want to export variable "AX" independently then use:

AX = 'name'
export AX

2. Exporting an independent variable followed by appending it to some existing variable

For example if you want to export variable "AX" independently followed by appending it to the class path then use:

AX = 'name'
export AX
PATH=$PATH:AX
export PATH



回答3:


Typically, variables are declared and defined in one place and exported in another:

AX='name'
export AX


来源:https://stackoverflow.com/questions/14524590/how-to-add-export-statement-in-a-bash-profile-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!