本帖最后由 import_key 于 2020-6-5 17:04 编辑
说明:
1、下面方法只能解决,当前登录的用户能够能够加载成功环境变量。
2、一旦切换su root环境变量失效, 在从su root切换回去,原本生效的环境变量,无效了。 (为什么登录的时候,在登录只加载了一次 /etc/profile , 切换用户的时候,没有执行这个 )
- # 在目录下新增一个shell文件 ,把环境变量写进去
- /etc/profile.d
- # 新增sh
- touch my.sh
- #
- vim my.sh
- # 内容如下
- export unixODBC_HOME="/usr/local/unixODBC"
- export PATH="$unixODBC_HOME/bin:$PATH"
复制代码
为什么可以这样写,是因为, /etc/profile 中是这样描述的。
- if [ "$PS1" ]; then
- if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
- # The file bash.bashrc already sets the default PS1.
- # PS1='\h:\w\$ '
- if [ -f /etc/bash.bashrc ]; then
- . /etc/bash.bashrc
- fi
- else
- if [ "`id -u`" -eq 0 ]; then
- PS1='# '
- else
- PS1='$ '
- fi
- fi
- fi
- # 读取路径下shell,并执行。
- if [ -d /etc/profile.d ]; then
- for i in /etc/profile.d/*.sh; do
- if [ -r $i ]; then
- . $i
- fi
- done
- unset i
复制代码
|