环境变量的4种配置方法
2016-06-27 00:54
441 查看
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中添加(对所有用户有效,不需要重新执行,但需要重新打开一个base shell,例如关闭CRT正在登陆着的session窗口或者再重新打开一个session窗口,在新的session窗口就可以查看到变量已经生效)
4.在用户目录下的.bashrc中添加(对当前用户有效,不需要重新执行,但需要重新打开一个base shell,例如关闭CRT正在登陆着的session窗口或者再重新打开一个session窗口,在新的session窗口就可以查看到变量已经生效)
# .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中添加(对所有用户有效,不需要重新执行,但需要重新打开一个base shell,例如关闭CRT正在登陆着的session窗口或者再重新打开一个session窗口,在新的session窗口就可以查看到变量已经生效)
4.在用户目录下的.bashrc中添加(对当前用户有效,不需要重新执行,但需要重新打开一个base shell,例如关闭CRT正在登陆着的session窗口或者再重新打开一个session窗口,在新的session窗口就可以查看到变量已经生效)
相关文章推荐
- Linux下Dialog+Shell三层目录专业规范跳板机脚本 推荐
- shell去除换行和空格
- shell脚本几个练习
- 在Oozie 中调度执行shell、hive 脚本,以及通过shell脚本执行hive/sqoop/shell脚本的方法
- 使用shc加密shell脚本
- Linux的环境变量.bash_profile .bashrc profile文件
- shell command:echo
- 【DAY2】hadoop 完全分布模式中需要用到的SHELL脚本
- shell下的sed命令
- 【DAY3】shell编程以及linux的其他设置学习笔记
- Shell脚本应用(五)if语句
- Shell编程速查手册
- linux下shell显示-bash-4.1#不显示路径解决方法
- 初学CentOS——shell脚本基础
- shell下的grep工具
- shell脚本应用(四)
- Xshell修改设置阿里云ECS主机名
- 关于shell脚本的一些容易混淆的概念
- LINUX shell 快捷键
- Shell脚本总结