码迷,mamicode.com
首页 > 其他好文 > 详细

环境变量的配置方法

时间:2016-06-27 12:29:33      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:环境变量

1.在用户目录下的.bash_profile中添加(在当前用户有效):

# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi


# User specific environment and startup programs


PATH=$PATH:$HOME/bin


export PATH

export a=123 #新添加环境变量

[root@localhost ~]# . .bash_profile

[root@localhost ~]# echo $a

123

[root@localhost ~]# su - cjf #切换用户

[root@cjf ~]$ echo $a #打印出来的是空置


2.在etc/profile中添加(对所有用户都有效)

 /etc/profile


# System wide environment and startup programs, for login setup

# Functions and aliases go in /etc/bashrc


# It‘s NOT a good idea to change this file unless you know what you

# are doing. It‘s much better to create a custom.sh shell script in

# /etc/profile.d/ to make custom changes to your environment, as this

# will prevent the need for merging in future updates.


pathmunge () {

    case ":${PATH}:" in

        *:"$1":*)

            ;;

        *)

            if [ "$2" = "after" ] ; then

                PATH=$PATH:$1

            else

                PATH=$1:$PATH

            fi

    esac

}

export b=789 #新添加环境变量

[root@localhost ~]# . /etc/profile

[root@localhost ~]# echo $b

789

[root@localhost ~]# su - cjf #切换用户

[root@cjf ~]$ echo $b  #必然能打印出来值

789

3.在/etc/bashrc中添加


环境变量的配置方法

标签:环境变量

原文地址:http://quguanhai.blog.51cto.com/1951497/1793109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!