2010-03-17 127 views
3

Linux/Unix环境变量保存在哪里?我如何添加自己的环境变量并使其持久化,而不仅仅是在当前正在运行的脚本中?Linux/Unix环境变量

+0

http://lowfatlinux.com/linux-environment-variables.html – 2010-03-17 08:08:00

回答

3

您可以将它们添加到您的个人资料中,例如~/.bash_profile。全局配置文件通常位于/ etc中。例如/etc/profile。如果你有,请看/etc/profile.d目录。

+0

我没有看到/ etc/profile文件,但我看到/etc/profile.d中哪些包含gvfs-bash-completion.sh和speechd-user-port.sh文件。我应该怎么做才能为所有用户添加环境变量? – 2010-03-17 08:26:17

+1

'/ etc/profile.d'中的是自定义配置文件。对于所有用户,如果你没有'/ etc/profile',那么创建它。 – ghostdog74 2010-03-17 09:17:18

1

要查看env变量,请使用printenv命令。

要设定新的变量,你可以使用~/.bash_rc文件:

export new_variable=10 

new_variable将是所有弹访问。

+0

谢谢。你的意思是〜/ .bashrc文件吗? 如何为所有用户设置环境变量? – 2010-03-17 08:24:38

+1

'='周围没有空格。 'export new_variable = 10'或者它不起作用。 – 2010-03-17 08:35:36

1

添加export语句~/.bash_login

+0

我没有看到〜/ .bash_login文件。我可以创建它吗? 〜/ .bash_login和〜/ .bashrc有什么区别? – 2010-03-17 08:27:08

+0

@alex您可以创建一个。 bash_login针对交互式shell运行登录shell和bashrc - 检查man page以获取详细信息。 – Amarghosh 2010-03-17 09:34:08