linux全局变量暴露

临时

临时设置,退出shell即小时

export  path=$PATH:tianzehao

永久

1、在/usr/bin先添加链接

比如python的变量,可以快速切换默认python2, 与python3


image.png

2、在/etc/profile 中暴露

export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
image.png

3、在/etc/profile.d中暴露

在文件夹下编写xxx.sh 暴露,原理是因为/etc/profile中回去加载

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

xxx.sh写法

export PATH=/opt/hadoop/bin:$PATH
export PATH=/opt/zookeeper/bin:$PATH
export PATH=/opt/hive/bin:$PATH
export PATH=/opt/hive/hcatalog/bin:$PATH
export PATH=/opt/tez/bin:$PATH
export PATH=/opt/hive/bin:$PATH
export PATH=/opt/hive/hcatalog/bin:$PATH
export PATH=/opt/hive/bin:$PATH
export PATH=/opt/hive/hcatalog/bin:$PATH
export PATH=/opt/hadoop/bin:$PATH
export PATH=/opt/hive/bin:$PATH
export PATH=/opt/hive/hcatalog/bin:$PATH
export PATH=/opt/kafka/bin:$PATH

6、当前用户 ~/.bash_profile设置

该文件一般会加载.bashrc

export PATH=/opt/hive/hcatalog/bin:$PATH
export PATH=/opt/kafka/bin:$PATH

4、当前用户域设置当前用户.bashrc文件

该文件一般会加载/etc/.bashrc
export PATH=/opt/hive/hcatalog/bin:PATH

5、当前用户 /etc/bashrc

export PATH=/opt/hive/hcatalog/bin:$PATH
export PATH=/opt/kafka/bin:$PATH

你可能感兴趣的:(linux全局变量暴露)