导出 PATH 在 linux 上的 bash shell 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35881004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
exporting PATH not working in a bash shell on linux
提问by Yet A-beyene
For example, I type to the following command:
例如,我输入以下命令:
# PATH=$PATH:/var/test
# echo $PATH
........./var/test // working
# export PATH
Next, I open another bash shell session to test if the export works by typing the following command:
接下来,我打开另一个 bash shell 会话,通过键入以下命令来测试导出是否有效:
# echo $PATH
........ // not working as in I don't see /var/test path
回答by riteshtch
you have set the PATH
environment variable only for your current bash
session. You need to add the line PATH=$PATH:/var/test
into ~/.bashrc
so that it works for any bash
shell.
您PATH
仅为当前bash
会话设置了环境变量。您需要将该行添加PATH=$PATH:/var/test
到其中,~/.bashrc
以便它适用于任何bash
shell。
Just run the following command to put it into your rc
(run commands) file (rc files contain startup information for a command(initialization)):echo "PATH=$PATH:/var/test" >> ~/.bashrc
只需运行以下命令将其放入您的rc
(运行命令)文件(rc 文件包含命令的启动信息(初始化)):echo "PATH=$PATH:/var/test" >> ~/.bashrc
More info: https://en.wikipedia.org/wiki/Run_commands
https://superuser.com/questions/789448/choosing-between-bashrc-profile-bash-profile-etc
更多信息:https: //en.wikipedia.org/wiki/Run_commands
https://superuser.com/questions/789448/choosing-between-bashrc-profile-bash-profile-etc
export
ing a variable makes it available only in child processes spwaned/started from that bash shell.
As an example:
export
使用一个变量使其仅在从该 bash shell 衍生/启动的子进程中可用。
举个例子:
$ export var=abcd
$ sh
$ echo "$var"
abcd
$ exit
$ echo "$var"
abcd
$
sh
is the child process of bash
hence it gets the value of var
, since you open a new bash
which is a different process altogether it does get the PATH
value.
sh
是 的子进程,bash
因此它获得 的价值var
,因为您打开一个新的bash
,这是一个完全不同的过程,它确实获得了PATH
价值。