Chinaunix首页 | 论坛 | 博客
  • 博客访问: 419442
  • 博文数量: 77
  • 博客积分: 2948
  • 博客等级: 少校
  • 技术积分: 912
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-16 15:34
文章分类

全部博文(77)

文章存档

2014年(9)

2013年(9)

2011年(26)

2010年(33)

分类: LINUX

2011-01-12 11:20:36

环境变量配置文件

1.环境变量文件:/etc/profile,/etc/environment,~/.bashrc(优先级1>2>3)
2.查看环境变量:env

修改用户环境变量

用户环境变量通常被存储在下面的文件中:

  • ~/.profile
  • ~/.bash_profile 或者 ~./bash_login
  • ~/.bashrc

上述文件在Ubuntu 10.0以前版本不推荐使用。

系统环境变量

系统环境变量一般保存在下面的文件中:

  • /etc/environment
  • /etc/profile
  • /etc/bash.bashrc

/etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。

加入环境变量

如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):

$ sudo nano /etc/profile

在里面加入:

export PATH="$PATH:/my_new_path"

你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:

$source /etc/profile

需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。

其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。



3.1 设置一个新的环境变量
$ export cool=”coool”#在变量里面不要用“!”(ubuntu export PATH="$PATH:/your path1/:/your path2/…..”)
$ echo $cool
coool

3.2 使用set命令显示所有本地定义的Shell变量
$ set
3.3 使用unset命令来清除环境变量
$ export cool=”coool” #增加一个环境变量TEST
$ env | grep cool #此命令有输出,证明环境变量TEST已经存在了
cool=”coool”
$ unset cool #删除环境变量cool
4.要使得刚修改的环境变量生效:source ~/.bashrc
 
阅读(8757) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~